Allows mod developers to spawn objects over the network with Mycelium, and still have IDs that are consistent across clients.
- Delete every reference to
PhotonNetwork.Instantiatein your mod. You useInstantiator.Instance.InstantiateObjectnow.- View how to use it here.
- Make sure you register your mod with Mycelium when it starts.
MyceliumNetwork.RegisterNetworkObject(this, YourPlugin.ModID);
- Make sure to register any GameObjects you will be spawning after this, and give it a network name.
MyceliumObjects.MyceliumObjects.RegisterGameObject("MySuperCoolName", gameObjectForSuperCoolObject);
- Use
Instantiator.Instance.InstantiateObjectto spawn objects.Instantiator.Instance.InstantiateObject("MySuperCoolName", YourPlugin.ModID, locationToSpawn, rotationIsOptionalToSpecify);
Network IDs are basically Photon View IDs. A MyceliumView is added to your component when it is made, if it doesn't already exist.
You can get the network/mod ID of the component by doing:
MyceliumView view = GetComponent<MyceliumView>();
Debug.Log(view.NetworkID);
Debug.Log(view.ModID);Warning
Make sure to check if the view is null before using it, as it may not exist yet. THE NETWORK ID WILL BE SET AFTER AWAKE IS CALLED so use Start to register the GameObject as a network object. See an example in my Landmines mod here