(Netcode) GameObject datatype as NetworkVariable

Hello!

I am trying to make my first multiplayer game in Unity using Netcode for GameObjects and have only a little experience i Unity. At first, most went well but now I am running into some problems. My main issue is that (as far as I have understood) you cant have GameObjects or other nullable datatypes as a NetworkVariable.

I have a gridmap and each tile has a script that holds a GameObject reference to what is currently occupying the tile. That works in singleplayer but I want to make this game multiplayer and thus I want to sync what GameObject is occupying each square and be able to access the GameObjects’ scripts. Other solutions which I have thought of that don’t use NetworkVariables seem inefficient and annoying so surely there is a way to work around the fact that you cannot use the GameObject datatype in Network variables? Is that the case, and if not, what is the best way to work around it?

Yes you can use. You can use Some structs like

[System.Serializable]
public struct ObjectStruct
{
    public GameObject gridObject;
}

and then you can create an variable. Add the GameObject reference and pass this parameter as NetworkVariable. Since the structs are not nullable you should be able to transfer your data.