- Home /
Question by
armandas2005 · Feb 16 at 05:46 PM ·
networkingclienthost
unity netcode object doesnt get declared on client when instantiated
I'm currently trying to program a tower defense game. I'm pretty new to netcode which is why I run into some problems. I just have the problem that if the client instantiates something that it is not declared for him. It is spawned on all clients but in the script of the client the object is still null.
public void SpawnObject()
{
if (IsServer)
{
instantiatedObj = Instantiate(objTOInst, new Vector3(0.7110749f, 0.32f, -0.09f), transform.rotation);
instantiatedObj.GetComponent<NetworkObject>().Spawn();
}
else
{
Debug.Log("executed");
SpawnOnServerRpc();
}
}
[ServerRpc]
void SpawnOnServerRpc(ServerRpcParams rpcParams = default)
{
SpawnClient();
}
void SpawnClient()
{
instantiatedObj = Instantiate(objTOInst, new Vector3(0.7110749f, 0.32f, -0.09f), transform.rotation);
instantiatedObj.GetComponent<NetworkObject>().Spawn();
}
instantiatedObj is null on the client even though it has been instantiated and spawned.
Comment
Your answer
Follow this Question
Related Questions
Why is the command function not being called on the client? 0 Answers
Object not updating on host 1 Answer
Multiplayer problem 1 Answer
Requesting data from server 1 Answer
Change collider size in Networking 0 Answers