- Home /
How do you access a photonNetwork.Instantiate Object
I am asking this question and replying the answer. This is only because I am not seeing it posted anywhere when I was learning how to do this.
Example** photonNetwork.Instantiate(PrefabName,transform.position,transform.rotation,0);
That is as far as any detailed example would go. I found that if you need to do more things after you have created this you would end up searching for hours.
You should post your answer below and accept it as answer, so your question does not appear in the list of unanswered questions.
Answer by Belangia · Apr 23, 2015 at 08:43 AM
a simple solution is to grab the PhotonView that will be created with the prefab.
change the code above to this instead.
PhotonView photonView = photonNetwork.Instantiate(PrefabName,transform.position,transform.rotation,0) .GetComponet();
you can then call scripts from that instanced object like so.
photonView.transform.gameObject.GetComponet().PublicMethod(Values);
Tid bit that I thought would help.
Answer by stefanplc · Dec 16, 2016 at 11:59 AM
In one of my scripts I had my object be instantiated inside OnJoinedRoom() and I wasn't able to access it outside of that function. A solution that I found however is that I could declare a GameObject variable and then assign the instantiated object to it. So something like this:
GameObject Player;
public override void OnJoinedRoom() {
GameObject Instantiate = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);
Player = Instantiate;
}
Hope this helps!
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Photon Networking Instantiating Problem 0 Answers
Photon Cloud, Multiplayer Damage script 0 Answers
Multiplayer Problem 1 Answer
Network.Instantiate is CHAOS. 1 Answer