Same Character for different player

aledg

New member
Hi guys, I'm using PUN.
To spwaning different characters I'm using the class in the documentation like this.


C#:
using UnityEngine;
using Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game;
using Photon.Realtime;

public class MySpawnManager : SpawnManagerBase
{
    
    protected override GameObject GetCharacterPrefab(Player newPlayer)
    {
        GameObject m_Character = Resources.Load<GameObject>(GlobalControl.MyAvatarModel);
        return m_Character;
    }

}

<< GlobalControl.MyAvatarModel is a String variables set in the prev scene.

It works and I can load different dynamic characters, but the problem is that the two users don't see different characters but they see the same characters that they have also selected for the opponent ...

1471

1472
 

Justin

Administrator
Staff member
What does GlobalControl.MyAvatarModel return? You'll need to ensure that you return a different model based on the Player parameter.
 

aledg

New member
Return a different model, in fact the player plays with the correct avatar, the problem that all other users have the same Avatar ...

For example

User1 selects blue avatar
User2 selects red avatar


User1 plays with blue avatar (but also sees User2 with blue avatar)
User2 plays with red avatar (but also sees User2 with red avatar)
 

Justin

Administrator
Staff member
How does that property know which model to select for each player? The same GetCharacterPrefab method is called for both the local and remote players so you need to ensure it is returning the correct model based on the player id. If you place a breakpoint in this method I bet that GetCharacterPrefab is returning the same object no matter what client joins.
 

aledg

New member
Thank right now it's clear, but Where I can find example or documentation to do that? I suppose that I've to binding the ID of the user to the character model and inside MySpawnManager class I've to spawn the right model
 

Justin

Administrator
Staff member
It really depends on your game implementation but it can be something as simple as:

Code:
[SerializedField] protected GameObject[] m_Characters;
...
    protected override GameObject GetCharacterPrefab(Player newPlayer)
    {
        return m_Characters[newPlayer.ActorNumber];
    }
 

NIOBruno

New member
Hello,

I'm having the same problem, did someone managed to solve this issue?
I would really appriciate if there is a solution for this problem.
 
Top