Question by
armandas2005 · Feb 17 at 10:02 AM ·
networkinginstantiatespawnclient
Problem with instantiating and declaring objects in Netcode on client
hey guys, does anyone know why "instantiatedObj" is not getting declared on client
public class HelloWorldPlayer : NetworkBehaviour
{
//public NetworkVariable<Vector3> Position = new NetworkVariable<Vector3>();
public GameObject objTOInst;
//public NetworkVariable<Transform> returnVariable = new NetworkVariable<Transform>();
public GameObject instantiatedObj;
public override void OnNetworkSpawn()
{
//Calling check function if player is Server or Client
if (IsOwner)
{
SpawnObject();
}
}
public void SpawnObject()
{
if (IsOwner)
{
//if server, object is spawned
if (IsServer)
{
instantiatedObj = Instantiate(objTOInst, new Vector3(0.7110749f, 0.32f, -0.09f), transform.rotation);
instantiatedObj.GetComponent<NetworkObject>().Spawn();
}
//else server RPC is called
else
{
SpawnOnServerRpc();
}
}
}
[ServerRpc]
void SpawnOnServerRpc(ServerRpcParams rpcParams = default)
{
PlayerRpc();
}
void PlayerRpc()
{
instantiatedObj = Instantiate(objTOInst, new Vector3(0.7110749f, 0.32f, -0.09f), transform.rotation);
instantiatedObj.GetComponent<NetworkObject>().Spawn();
}
}
it is spawned but instantiatedObj is somehow still not declared in inspector
Comment
Your answer
Follow this Question
Related Questions
Networking - How do i spawn an object with client authority? 1 Answer
[UNET] Spawn object on server BUT delete on your client 1 Answer
How can i Spawn a different prefab for client? 0 Answers
Networking - Host can spawn objects but client cant 0 Answers
MLAPI Client Character Spawning Problem 0 Answers