[Solved] [Help] Networked Instantiation doesn't work

Options
Hello Photon Community,

I am having trouble with my networked instantiation.
I am building a UI-only-Game. My Player-Prefab is basically an Image, that needs a Canvas as a parent.
When I use 'PhotonNetwork.Instantiate()' I successfully instantiate my Player-Prefabs across all Game Instances. However they aren't parented and therefore aren't displayed.
If this was a one-player game I'd use GameObject.Instantiate(object, position, rotation, parent). The parenting process is done automatically for me. Does this work with PUN somehow? Or do I have to manually tell all game instances to reparent all Player-Objects via an RPC or such?

Thank you very much for your help.
Béla

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Capricornum,

    Thank you for choosing Photon!

    You need to do the parenting yourself.
    You need to tell other clients which parent to add the instantiated object to if they can't guess it.
    If they can guess it, just do the parenting yourself manually on each client once the object instantiated.
    Otherwise, you can use:

    1- Manual instantiation
    2- Instantiation data
    3- RPC
    4- RaiseEvent
  • Hi JohnTube,

    thanks a lot for your answer. The links you provided are helpful. The manual instantiation makes sense to me. I think I could solve my problem that way.
    Can you just explain to me what you mean with "if they can guess it"?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Capricornum,

    Can you just explain to me what you mean with "if they can guess it"?
    I mean if the parent is static or predefined or you can "calculate" it from prefab name or from PhotonView or owner actor number, etc. No need to send extra info to identify the parent GameObject in this case.
  • Ok, I understand. Thanks a lot. I got it fixed :-)
  • Upon trying the manual instantiation process that JohnTube linked in his first comment. I ran into the issue, that apparently "only the master client is allowed to allocateSceneViewID's". I was trying to run the SpawnPlayer() method from the link on every client. That error message was displayed in the console.

    So am I supposed to spawn players only from the master client? And then tell all the other clients, "hey that's your Photon View and that's yours, and the last one is yours" using TransferOwnership?

    I'd be grateful for any insight on this.
    Thank you.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Capricornum,

    There is a difference between "allocate scene view ID" and "allocate view ID".
    The method to be used is PhotonNetwork.AllocateViewID and not PhotonNetwork.AllocateSceneViewID.
  • Well I'll be damned. That must have been auto correct. I was trying to copy paste the original from your link.
    Thank you very much!
  • Is it possible to mark this question as answered? I can't seem to edit the title anymore.