[Solved] Creates the object twice

Hello,
I have something strange which I can't fix that :(
First of all, I create the Player object and after there in the his script (For example Player Controller) I want to create for his "Player Canvas" object.

What I did (In the script PlayerController which on the Player):
<pre><code>private void Start()
{
GameObject pCanvas = PhotonNetwork.Instantiate("Player Canvas", Vector3.zero, Quaternion.identity, 0);

playerCanvas = pCanvas.GetComponent<PlayerCanvas>();
playerCanvas.Initiate(gameObject.transform, pView.owner.name);

if (pView.isMine)
pCanvas.transform.GetChild(0).GetComponent<ChatBallon>().ActiveChatInputField();
}</code></pre>

The problem is when I'm as master joined to the room, all works fine. But, When the client is connects to the room, I see two more objects.
I want to see only one object which have "Player1_UI (The Player Canvas object)" for every Player.

What happens in the scene (objects): "Master, Master_UI", "Client, Client_UI", and more two objects "Player Canvas(Clone), Player Canvas(Clone)".
For example what I want to will happen in the scene (objects): "Master, Master_UI", "Client, Client_UI", Without these two objects ("Player Canvas(Clone)").

When the master is alone:
291fdir.png
And when the client connects:
14mrkom.png

What I did wrong?

I hope you understand me.
Thanks! :)

Comments

  • Anyone? I really need help, I tried my ideas and nothing helps. :(
  • You only need one Player Canvas in the room? Even if that means only one player can affect it??
    You will have to check that only one player Instantiates the Player Canvas. Do it (e.g.) only when you joined a room and you are the Master Client (check: PhotonNetwork.isMaster)...
  • Tobias wrote:
    You only need one Player Canvas in the room? Even if that means only one player can affect it??
    You will have to check that only one player Instantiates the Player Canvas. Do it (e.g.) only when you joined a room and you are the Master Client (check: PhotonNetwork.isMaster)...
    No, I mean that every Player who join to the room will have the Player Canvas object (For example "Player2_UI").
    What happens is when someone (Client) connect, I see the "Player Canvas(Clone)" and more one like this "Client_UI".
    So, "PhotonNetwork.Instantiate" Creates the object twice instead of once.
    - You can see the Pictures.

    Thanks for answering. :)
  • It's probably not the best idea to instantiate everything in a Start() method. This could be called whenever someone joins (that would explain things).
    Check out the Marco Polo Tutorial "Adding Monsters".
    http://doc.exitgames.com/en/pun/current ... marco-polo

    "... In OnJoinedRoom, we call Instantiate ..."
  • Tobias wrote:
    It's probably not the best idea to instantiate everything in a Start() method. This could be called whenever someone joins (that would explain things).
    Check out the Marco Polo Tutorial "Adding Monsters".
    http://doc.exitgames.com/en/pun/current ... marco-polo

    "... In OnJoinedRoom, we call Instantiate ..."
    Yes, I know it.
    But, I connecting to the server in Menu scene and then OnJoinedRoom calls it at Menu scene. So, When new level loaded I called the PhotonNetwork.Instantiate for create the Player.

    Doesn't matter, I fixed it, there was bug! Anyway thank you. :)
  • I know its super necro, any chance on sharing what the bug you found was I am having the same problem.
  • Megalon3k said:

    I know its super necro, any chance on sharing what the bug you found was I am having the same problem.

    Seconded. I am having a similar issue (player spawns twice) and really need to find the answer but I have had no responses and can't find the answer online anywhere.
  • did you guys find the answer???