GameObject.Find and Unet

Hi ,

Got a little problem here that I can’t solve by myself.

Heres is the code, all in one script

public class WarriorSpells : NetworkBehaviour {

    [SyncVar]
    private int MurWallnom;



    private float CooldownSortWarriorA = 5f;
    private float CooldownSortWarriorZ = 1f;
    private float CooldownSortWarriorE = 2f;


    private bool BoolenSortWarriorA = false;
    private bool BoolenSortWarriorZ = false;
    private bool BoolenSortWarriorE = false;

    public GameObject MurWallPrefab;

    private GameObject cloneClient;
    
    public GameObject PrefabMurWallServeur;
    public GameObject Warrior;
    private GameObject clone;
    private float ProjectionWallRepere = 0;



    [Command]
    public void Cmd_ApparitionMur()
    {
        MurWallnom = MurWallnom + 1;
        clone = (Instantiate(MurWallPrefab, Warrior.transform.position, Warrior.transform.rotation) as GameObject);
        clone.transform.parent = transform;
        NetworkServer.Spawn(clone);
        clone.transform.name = clone.transform.name + MurWallnom;
        Debug.Log(clone.transform.name);
        
       
    }

    [Client]
    void MurEnfantGuerrier()
    {
        Debug.Log("ClientEnfantWall");
        cloneClient = GameObject.Find("MurWarrior(Clone)");
        cloneClient.transform.name = clone.transform.name + MurWallnom;
        cloneClient.transform.parent = transform;
        Debug.Log("ClientEnfantWall2");
        Destroy(clone);

    }


    // Use this for initialization
    void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {



        if (Input.GetKey(KeyCode.A))
        {
            if (BoolenSortWarriorA == false)
            {

                BoolenSortWarriorA = true;
                Debug.Log("SortA");
                Cmd_ApparitionMur();
                MurEnfantGuerrier();
               // StartCoroutine(CooldownSortA());

            }
        }
}

The error message is this :

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

That means that the line cloneClient = GameObject.Find("MurWarrior(Clone)"); hasent found anything

Problem is that MurWarrior(Clone) actually exist in the scene because it is spawned from the server

clone = (Instantiate(MurWallPrefab, Warrior.transform.position, Warrior.transform.rotation) as GameObject);

In the client scene, the name of the Gameobject is actually MurWarrior(Clone). Why does the engine dosent found the gameobject ?

Best regards,

Why do you Change the Name in line 35 after you NetworkServer.Spawn()'ed the Object?

Ok so if I understand this correct Cmd_ApparitionMur is executed on the server.

So there will be some delay until the server gets it, executes it and spawns the object for all clients. By the time your client spawns the object, you’ve already entered and executed MurEnfantGuerrier.

So what I mean is, your game object is spawned a few milliseconds after you expect to have it. This is why you notice it in the editor and scratch your head about your code. To you it seems instantanious. To network and code, it is not. It’s asynchronous.

Send a message back from the server to the client when it is ready.

I rename the gameobject on the server to track the for further use, tested with these lines on comments still got the problems