Player controllers already exist issue
Options
FGStud
✭
Hello,
I PhotonNetwork.Instantiate my player and seperately PhotonNetwork.Instantiate the controls (Canvas UI button, joystick for mobile game).
When 1 player is in the room alone all is fine.
When a player joins I get an error that the player controls already exist. This causes the original and newly joined character to lose all their controls (ie buttons/joystick don't work).
I tried combining the controls into the player prefab but since it's a canvas that didn't work.
How can I fix this?
Update:
This is what I do to find the controls to use in player script:
I PhotonNetwork.Instantiate my player and seperately PhotonNetwork.Instantiate the controls (Canvas UI button, joystick for mobile game).
When 1 player is in the room alone all is fine.
When a player joins I get an error that the player controls already exist. This causes the original and newly joined character to lose all their controls (ie buttons/joystick don't work).
I tried combining the controls into the player prefab but since it's a canvas that didn't work.
How can I fix this?
Update:
This is what I do to find the controls to use in player script:
void Start ()
{
m_PhotonView = GetComponent<PhotonView> ();
if( m_PhotonView.isMine == true )
{
FlyJoystick = GameObject.Find("FlyJoystickInstNet").GetComponent<ETCJoystick>();
FlyJoystick.onMove.AddListener( On_Move_Flyjoystick);
FlyJoystick.onMoveEnd.AddListener( On_Move_End_Flyjoystick);
landButton = GameObject.Find("landButtonInstNet").GetComponent<ETCButton>();
landButton.onUp.AddListener( On_LandButton_Up);
flyButton = GameObject.Find("flyButtonInstNet").GetComponent<ETCButton>();
flyButton.onUp.AddListener(On_FlyButton_Up );
fireButton = GameObject.Find("fireButtonInstNet").GetComponent<ETCButton>();
fireButton.onDown.AddListener(fireHandler );
ForceSlider = GameObject.Find("SliderInstNet").GetComponent<Slider>();
}
}
0
Answers
-
Hi,
What is the purpose of creating controls via PhotonNetwork.Instantiate? I guess you do not need to synchronize controls across network. So process them as plain Unity objects. Or at least disable them on non-owning clients (check PhotonView.isMine).1 -
Good question. Not sure why I needed to do that.
I went ahead and left it the way it was and added isMine checks but still got player controls already exist message and no player could be controlled. Same issue.
I changed to simply instantiating the controls (not PhotonNetwork.Instantiate) and now local controls move remote player and remote controls move local player. They are backwards.
Any ideas what to check?0 -
Could this also be the wrong camera following the wrong player?
I have my player prefab that I PhotonNetwork.Instantiate. This prefab has the camera for the player as a child. No fancy follow. Just a child of the parent main game character.
Could that be the issue?0 -
Update: Having the camera as a child of prefab was the issue.
I would still prefer to have it be the child of the prefab character (looks better when playing) but as of now it's not working.
I moved camera out of prefab and set it's target to PhotonNetwork.Instantiate 'd player (as in robotKyle demo) and it all works.
Not the perfect solution but workable for now.
0 -
In the Start method, disable everything that your player doesn't own.
if (!Photonview.isMine)
{
// Camera disable
// Script unique for your player disable
// etc.
}
Edit :
This way, just the camera of your player will be enable. And you can let the camera in your prefab0