Does PhotonNetwork.Instantiate call the new GameObject's Start method ?

Hello,

First, I am following the PUN tutorial on the Photon web site.

In my game, I have a GameManager, a PlayerManager and a PlayerUI (and others but these three cause me some problems). In my GameManager Start method, I instantiate the local player which has a PlayerManager component. Because I use PhotonNetwork.Instantiate, this is sync on each client game, right ?

In the PlayerManager Start method, I call Unity's Instantiate method for creating a new PlayerUI. For the local player all is ok, but when a new player joins the room, a new PlayerManager appears in the hierarchy, but the Start method was not called, so there is no PlayerUI object created for him.

Why ?
Thanks

Best Answer

Answers

  • Hi @Mimon,

    Because I use PhotonNetwork.Instantiate, this is sync on each client game, right ?


    Yes, when you use PhotonNetwork.Instantiate, you actually instantiate a certain object for yourself and send this instantiation call to the server. Each client who is currently in the same room or joins this room later on will receive this call and instantiate the certain object.

    In the PlayerManager Start method, I call Unity's Instantiate method for creating a new PlayerUI. For the local player all is ok, but when a new player joins the room, a new PlayerManager appears in the hierarchy, but the Start method was not called, so there is no PlayerUI object created for him.


    When the second clients has joined the room, he will network-instantiate his own player prefab. When this one is created on the first client, you will have a second PlayerManager in the hierarchy. This is a wanted behaviour. Are you sure that the Start function is not called?
  • Does the second client send his own PlayerManager through the network, or does he ask the other clients to instantiate their version of it ?

    The Start method may has been called on the second client game, so the PlayerUI exists in it, but I thought that Start method would have been called on each client's game during the instantiation ...
  • That is exactly what I understood from the tutorial, so I don't know where my problem comes from. I will check and tell you if I found a solution.

    Thank you for your answers !
  • I tested with some logs, and it seems that the Awake method is called for each PlayerManager created (locally or through the network), but the Start method isn't called. My log was at the very beginning of the method so no if statement could have blocked it.
  • Have you already tested if the Basics Tutorial demo from the PUN package is working for you? If not, please do that and let me know, if this is working for you. If so, there is either a mistake somewhere in your project or on the related documentation page which we have to find.