[UNET] The thing you tried to instantiate is null(spawning objects over a network)
Hi there,
I'm building an Online FPS using Unet, wich works as expected. Everything works exept throwing grenades. It gives me an error called "The thing you want to instantiate is null" well only on the clients. The host can throw grenades perfectly fine, and the clients can also see the grenades.
The grenade prefab itself, consists of a rigidbody, network identity, network transform, and the projectile script(wich inherits from networkbehaviour)
The player instantiates the grenades using this piece of code:
[Command]
public void CmdThrowLethal(GameObject _lethal)
{
GameObject _lethalClone = Instantiate(_lethal, ThrowPoint.transform.position, ThrowPoint.transform.rotation) as GameObject;
NetworkServer.Spawn(_lethalClone);
}
ThrowPoint is just an empty gameobject put in the camera, so that it rotates with the camera and you can throw grenades where you're pointing. However the script above sits on the player object itself and not on the ThrowPoint object(maybe this causes problems).
I simply made a public variable for the grenade object on the script and dragged the grenade prefab from the assets folder to the variable in the inspecter.
public GameObject Lethal;
Then the method to throw the grenade gets called using this:
if(Input.GetKeyDown(KeyCode.G))
{
if (isLocalPlayer)
{
CmdThrowLethal(Lethal);
}
}
In the Update() method.
Also I've put the grenade prefab in the Registered Spawnable Prefabs array on the NetworkManager, so that cannot be the problem.
I tried to get it to work, but the only one who can throw a grenade is the Host itself, Clients just get the error. However the client can see the Host throwing grenades, so the grenade objects get synced.
I hope someone can help me.
Sidenote, I'm not a native English speaker so if something is unclear, please notify me.
Your answer
Follow this Question
Related Questions
how do i remember a just instantiated prefab as a variable gameobject? 1 Answer
Return key triggering a button OnClick? 1 Answer
Objects are created in the same location. 0 Answers
Suggest best hosting server for multiplayer Game??? 0 Answers
Accessing variable from another gameobject does not work 2 Answers