If you look at the docs for SyncVar (http://docs.unity3d.com/ScriptReference/Networking.SyncVarAttribute.html) there’s a tiny point that I missed on my first SyncVar try too: “Only simple values can be marked as [SyncVars]”. What this means is that SyncVars have to be primatives; classes aren’t supported. You have to build your own syncing for any classes. I can’t say if that’s different for GameObjects. I’m still working through syncing myself, but here’s a great resource I’ve found: https://www.youtube.com/watch?t=49&v=NLnzlwCRjgc. He specifically covers player syncing very well. Good luck!
That is what I am currently using, NetworkInstanceId + FindLocalObject.
I am on the latest release 5.1.2p3 and syncvar for GameObjects doesn’t work.
[SyncVar]
public GameObject test;
...
public override void OnStartServer()
{
test = (GameObject)Instantiate(prefabPlayerCam, prefabPlayerCam.transform.position,
prefabPlayerCam.transform.rotation);
}
The variable test will always be null on the server and on the client if I mark it with SyncVar.
public GameObject test;
...
public override void OnStartServer()
{
test = (GameObject)Instantiate(prefabPlayerCam, prefabPlayerCam.transform.position,
prefabPlayerCam.transform.rotation);
}
By removing SyncVar from the GameObject, the GameObject is now not null on the server but is null on the client as expected.
I think this might be a bug? I am on Windows 10 x64 if that has any relevance.
Edit:
And yes “prefabPlayercam” has a NetworkIdenty script attached.
Edit:
I just forgot to spawn it. It seems to be working now, thanks!