'Unity c# Photon - Set Parent of PhotonNetwork.Instantiate object

What I'm trying to do is set the parent of new tool and make it visible on the server like 'PhotonNetwork.Instantiate'

var drop = PhotonNetwork.Instantiate("Tools/Weapons/" + Tool.name, transform.position, Quaternion.identity);
            
drop.transform.SetParent(collider.gameObject.transform.GetChild(0).GetChild(0));


Using drop.transform.SetParent it's only visible for the local player.

If you have any questions, ask :)



Solution 1:[1]

Example: Set tag for parent object "Parent". Then you can find the object through this code: parent = GameObject.FindGameObjectWithTag("Parent").transform;

Solution 2:[2]

The right way Photon want you to do it is by using the "Custom Instantiation Data" https://doc.photonengine.com/en-us/pun/current/gameplay/instantiation

For example...

//1) The script where we you instantiate the object will pass the relevant data (The parent View ID):
  int parentViewID = PhotonView.Find(this.gameObject.getComponent<PhotonView>().ViewID);
  string word = "example";
  object[] myCustomInitData = new object[3];
  myCustomInitData[0] = parentViewID;
  myCustomInitData[1] = word; 
  
  PhotonNetwork.Instantiate(Path.Combine("Players", "Player" transform.position, Quaternion.identity, 0, myCustomInitData);
    
//_______________________________________________________________________    

//2) The script that attached to our new Instantiate object:
//Make sure the prefab has PhotonView component on it !
  
  using Photon.Pun;

  public class RandomCall : MonoBehaviourPun, IPunInstantiateMagicCallback
  {
    GameObject parent;
    public void OnPhotonInstantiate(PhotonMessageInfo info)
    {
        object[] instantiationData = info.photonView.InstantiationData;
        parent = PhotonView.Find((int)this.customInstantiateData[0]).gameObject;
        string word = (string)instantiationData[1];
        this.transform.setParent(parentObject)
    }
  }

Solution 3:[3]

You may want to look at the DataFrame.append method: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html

It adds rows to a DataFrame

You could use something like the following:

for i in [1, 3, 4]:
    df = df.append({'id':i, 'value1': 0, 'value2': 0}, ignore_index=True)

If you want them to be in order by id afterwards, you could sort it:

df.sort_values(by=['id'], inplace=True)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LuuSang
Solution 2
Solution 3 Vayun