hey having some trouble my [Command] Cmdspawn() will not run i can put the debug line just before i call it and it prints after isOwned, i have read something about gameobjects as an array int or something i don’t know how that works any solutions or tips that would be handy i don’t understand why it will not run it was working fine before i put the dictionary in there please and thankyou!
public void TaskOnClick()
{
if (spawnLocation == null)
{
spawnLocation = RequestDictionary();
}
if (isOwned)
{
CmdSpawn();
}
}
[Command]
public void CmdSpawn()
{
Debug.Log("Boo");
// GameObject spawnLocation = GameObject.FindGameObjectWithTag("ArcherSpawnLocation");
GameObject unit = Instantiate(unitToSpawn, spawnLocation.transform.position, Random.rotation);
unit.transform.position = Random.insideUnitSphere * 3f + spawnLocation.transform.position;
unit.transform.SetParent(null);
NetworkServer.Spawn(unit, connectionToClient);
spawnLocation = null;
}
private GameObject RequestDictionary()
{
if (!isOwned) { return null; }
NetworkIdentity identity = buildingSelect.GetBuilding().GetComponent<NetworkIdentity>();
int clientID = identity.GetInstanceID();
SpawnTroop spawnTroop;
if (buildingSelect.SpawnPoints.TryGetValue(clientID, out spawnTroop))
{
spawnLocation = spawnTroop.Location;
}
return spawnLocation;
}
}
found that if i run the client on the build i get a null reference of the spawn location, when i run client on the editor the reference to the spawn location in the inspector is filled but it doesn’t sync it seems to sync with running as a host.
i tried playing around with sync dirty/objects and sync time interval but there all internal and its probably best not to play around with the mirror code not that i could get it to work when i was playing around.
so how would i sync the game object i have read that you cannot sync the game objects over the network but you can use an int or the uint the netId or assetId, i do not understand how that looks in code i have tried typing out how i think it would work and have been looking for how i can get the ID but and can get that but transferring it back into a game object for the instantiation location, I’m so confused about that. im confused as to why spawnLocation it is available in the inspector as client on the editor but it says its null when i run the command from build