Netcode for GameObjects: NetworkSpawn() not working, something about _initializeVariables()

I’ve been watching a lot of tutorials on Unity Netcode-for-GameObjects, to try to replicate it into my card game, try to spawn a card logic object but it doesn’t work, at NetworkSpawn() it always has a problem with method IntializeVariables()

The Error says:

NullReferenceException: Object reference not set to an instance of an object

It points to this part in NetworkBehaviour:

for (int i = 0; i < NetworkVariableFields.Count; i++)

This is the method in which the error is found.

internal void InitializeVariables()
    if (m_VarInit)
    m_VarInit = true;
    if (!__rpc_func_table.ContainsKey(GetType()))
        __rpc_func_table[GetType()] = new Dictionary<uint, RpcReceiveHandler>();
        __rpc_name_table[GetType()] = new Dictionary<uint, string>();
        // Create index map for delivery types
        var firstLevelIndex = new Dictionary<NetworkDelivery, int>();
        int secondLevelCounter = 0;
        for (int i = 0; i < NetworkVariableFields.Count; i++)
            var networkDelivery = NetworkVariableBase.Delivery;
            if (!firstLevelIndex.ContainsKey(networkDelivery))
                firstLevelIndex.Add(networkDelivery, secondLevelCounter);
            if (firstLevelIndex[networkDelivery] >= m_DeliveryMappedNetworkVariableIndices.Count)
                m_DeliveryMappedNetworkVariableIndices.Add(new HashSet<int>());

This is my current code on the ServerRpc:

GameObject cardGameObject = Instantiate(cardLogic);
NetworkObject networkObject = cardGameObject.GetComponent<NetworkObject>();

At one point it was a lot more elaborate but it kept not working so I stripped out code to make it as simple as possible.

It has a network object, it is on the network prefab list, it is a NetworkBehaviour

Please help!

I’ve been stuck for over a week now with no progress!

I’m considering moving my project to mirror or some other network solution if this cannot be resolved!

I believe the part that could be null is NetworkVariables.

I actually removed all network variables to get this object to spawn, if I add a Network variable, the error moves to the part of the method _initializeVariables()

If I go to Implementation of _initializeVariables I get:

        internal virtual void __initializeVariables()
#pragma warning restore IDE1006 // restore naming rule violation check
            // ILPP generates code for all NetworkBehaviour subtypes to initialize each type's network variables.