PhotonNetwork.Instantiate Players as Child of empty game object...

I'm using the standard Unity method to instantiate new items into a parent via the GameObject.Transorm.Parent method. I am using with the Photon method to instantiate but it only childs the first player into the GameObject with all other players being placed into the root (I think this is because Photon takes over after the first instantiation).

Here is my base code with the PlayerFolder being set in the inspector to an empty GameOject in the root of the hierarchy:

public Transform PlayerFolder;

// Instantiate player

GameObject NewPlayer = PhotonNetwork.Instantiate(PlayerPrefab.name, StartPosition, Quaternion.identity);

NewPlayer.transform.parent = PlayerFolder;

NewPlayer.gameObject.name = string.Format("{0}: {1}", NewPlayer.gameObject.name, PhotonNetwork.NickName);

How do I tell Photon to instantiate ALL players as children of the of the same parent object?

Or if this is not currently possible, then how do I submit this as a new feature request?

P.S. I'm doing this because I'm NEW to Photon and I can't find a way of getting the transform.position of all players within  PhotonNetwork.LocalPlayer or PhotonNetwork.PlayerListOthers.

Answers

  • hello, it seems to me that on the computer that executes this code, the player will be childed correctly. however, on other computers, they only receive a message to create a player and nothing else (because PhotonNetwork.Instantiate will call the instantiation on all connected machines).


    If you want everyone to take their networked player object and child it to something, you'll need to send a network message, probably best to use an RPC, or you can try using instantiationData, which you can pass in as an argument to PhotonNetwork.Instantiate.

  • DiGiaComTech
    edited November 23

    What I'm really trying to do on each client is rotate the name/health banner of non clients towards the client player's camera (using Unity's LookAt function for example). So I need to do this in the update method of each player object in the hierarchy that is not my player object ... and that probably needs to be done after Photon repositions them.

    I suppose I could build and manage a dictionary of player GameObjects via the Photon OnJoin & OnLeave events and reference that vs. trying to FIND specific things in the Unity scene hierarchy :(

    But I think I understand you comment ... my client code instantiates me, but joining players are instantiated in my client by Photon's back end code. Anyway, just starting to learn Photon ... got a long way to go ;)