How to setup a instantiated gameobject with mirror networking correctly?

In my procedural game worlds, I have a habitus of instantiating new objects like this:

GameObject character = (GameObject.Instantiate(characterPfb, location.position, 
location.rotation, transform));
DragAndDrop dnd = character.GetComponent<DragAndDrop>();
dnd.startPos = location;
dnd.mainCam = Camera.main;
dnd.gameState = gameState;

So I create the gameobject, get its script and fill it with all variables it needs to function.
Now, this doesn’t seem to work with mirror since the fields stay empty in the new object.
I have tried to pass all the variables to the Player script and let it set the variables via command.
Still, the fields remain empty.
I hate networking for how everything that would otherwise just work perfectly has simply no effect at all. As if I’d write all the code for nothing.

I would be very happy if someone could redeem me, and show me how to set up an instantiated gameobject correctly with mirror, so it has all its variables set.

Thank you!

Hi, Im a beginner with Mirror as well, but was thinking, maybe change the variables and then call NetworkServer.Spawn ? I’m pretty sure this will fix your problem

public class SpawnOnNetwork: NetworkBehaviour

    [SerializeField] private GameObject prefab;
    private void Update()
        if (!isLocalPlayer) return;
        if (Input.GetKeyDown(KeyCode.A)) CmdSpawn();

    [Command(requiresAuthority = false)]
    private void CmdSpawn()
        GameObject object = Instantiate(prefab);

        // change your values here
        object.tag = "Item";

^ this script is just a similar example

// note you will need to have your prefab drag into / registered in the NetworkManager under registered spawnable prefabs, and it needs to have a network identity!


Thanks guys, now it works!