Prefab can not be instantiated over the network.

Options
I have been having this problem for a while and I have failed to solve it. My problem is simple. I have a prefab in my resources folder. I have two clients in a room the master and the non-master client. The master client is the first one to join a room and it has it's prefabs instantiated(a ball, an infield player and a goal keeper). When the second player gets into the room he has to instantiate his own prefabs(same as player one). The problem is the ball only gets instantiated by the master client and the second player doesn't instantiate the ball. Another thing is after running the logic to run the ball the ball variable on the MatchManager script changes from 'None (BallRoot)' to 'Missing BallRoot', which makes me think the ball is being created and then somehow destroyed. The player and the goal keeper gets instantiated successfully on the network by the second client when he joins the room.

Here is my logic for instantiating the ball
BallRoot = PhotonNetwork.Instantiate(BallDB.Balls[UserControllerData.SelectedBallIndex].name, BallSpawnPoint.position, BallSpawnPoint.rotation, 0) .GetComponent<BallRoot>();
I realized that if there is client that has already instantiated the ball then the other client won't be able to instantiate the ball by wrapping the instantiate ball logic inside an 'if client is not master' logical statement like this.
if(!PhotonNetwork.isMasterClient) { BallRoot = PhotonNetwork.Instantiate(BallDB.Balls[UserControllerData.SelectedBallIndex].name, BallSpawnPoint.position, BallSpawnPoint.rotation, 0) .GetComponent<BallRoot>(); }

The ball gets instantiated on the second player and the ball variable on the 'MatchManager' script is set properly.

So how do I fix this problem

Best Answer

  • Wasu_Studio_01
    Answer ✓
    Options
    Mine was a programming error. I was using the singleton pattern on the ball. I had to remove it for it to work.

Answers

  • Wasu_Studio_01
    Answer ✓
    Options
    Mine was a programming error. I was using the singleton pattern on the ball. I had to remove it for it to work.