Network.Instantiate is CHAOS.

TL;DR At the Bottom.

I honestly did not have any other idea of how to name this thread.

Network.Instantiating objects is completely random.

From the start:

I’m making a first networking game project to teach myself how to do it. A simple, 3 player shooter.

Of course I have watched and read tutorials for days now and implemented everything accordingly.

When a Player enters the game, he is being spawned. Right after that, his mesh is separately Network.Instantiated and childed to him (due to an option to change your character skin via Playerprefs).
In the game itself, the Players can change weapons, from 1 to 3 (knife, pistol, shotgun, basics). These weapons are made through Net Instantiate too - at weapon change the current weapon is Net.Destroyed and a selected one is Net.Instantiated.

As long as in the game is only one player - all’s fine. Now the problem is - the outcome of NetInstantiating is almost always random when a second player enters.

The parenting of instantiated objects sometimes works, sometimes not, their scaling is most of the times screwed up, the Objects often appear at V3(0,0,0) or at their desired spawn point, they are getting Instantiated in multiple copies scattered around the scene… it’s just a fire-engulfed Jason Polloc paining.

SO FAR I have tried several different configurations of NetworkView.isMine, changing RPC functions, messing with NetView.vieid’s and so on and so on. Heck, I even added NetworkViews on EVERYTHING in an act of a Weltschmerz agony. Not mentioning animations not playing over network but that’s a different matter.

The Internets are getting even worse when it comes to googling my answers, because everything just doesn’t work as intended or there’s no intel on these issues.

TL;DR / CONCLUSION

Can anyone create a simple (JavaScript prefered though not required) example of a script, which on demand of only his owning Player spawns and parents a single Object, (like a script, that instantiates a child weapon on player parent), so it can be used as a template for future creations?
Thank you, kind adventurer, in advance. You’re saving lifes right now.

I’ll be honest, your question truly was tl;dr so thanks for that last synopsis. Check out this guy: Multiplayer FPS in Unity 3d, Part 1: Introduction & Project Setup - YouTube on how he makes a multiplayer shooter. It’s really clear and helpful. He uses Photon Unity Networking but the concepts and code are mostly the same or similar. I.e. Instead of Network.Instantiate it’s PhotonNetwork.Instantiate.

A simple way to instantiate something and child it is to use an RPC to instantiate rather than Network.Instantiate.

public GameObject Gun; //The gun to instantiate.
public GameObject Player; //Represents the player for the gun to be attached to
[RPC]LeInstantiate()
{
GameObject LeGun = Instantiate(Gun, Vector3.zero, Quaternion.identity) as GameObject;
LeGun.transform.parent = Player;
LeGun.AddComponent<NetworkView>();
}