0

enter image description here

public void CmdCreateSelection()
    {
        List<GameObject> myLocalList = new();
        for (int i = 0; i < cardsPrefab.Count; i++)
        {
            GameObject card = Instantiate(cardsPrefab[i], holder);
            card.tag = "CreateDeck";
            card.GetComponent<CardType>().prefab = cardsPrefab[i];
            myLocalList.Add(card);
            NetworkServer.Spawn(card);
            TargetCreateSelection(card.transform); <----------- ERROR OCCURED HERE 
        }

    }

    [TargetRpc] 
    public void TargetCreateSelection(Transform card)
    {
     card.SetParent(holder,false);
    }

After changing the Scene froom Lobby scene to game scene, instiating the cards on server,use TargetRpc to tell other clients, to parent specified card, spawned on server, but get an error.

Object on which this code is called is a sceneObject, which is inactive before the player load scene.

Using Mirror.

Already trying to call TargetCreateSelection, without any action in method, but same error occurred.

Couldn't understand why this error occurred.

Why Error occurred and how to fix it ?????????

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Do your `cardsPrefab`s have a `NetworkIdentity` component? and does the object this script is attached to also have one? This script should be attached to your player object .. is it? – derHugo Nov 21 '22 at 06:58
  • 1) CardsPrefab as well as Object on which this scipt attached to have a NetworkIdentity. 2)The idea, that when players change scene, CardSelection script attached to GameObject, which already on this current scene, instantiate a cards, and then spawn it on the clients. – Oleksii Nov 21 '22 at 19:50
  • `which already on this current scene` is probably the issue I guess it isn't owned by anyone so you can't use it to call an RPC on it ... I guess you would need your local player to trigger the RPC and then on remote side find this object and let it do its magic – derHugo Nov 22 '22 at 07:23
  • "you would need your local player to trigger the RPC and then on remote side find this object and let it do its magic", but how to do that ? – Oleksii Nov 22 '22 at 19:12
  • When my localplayer triger Rpc this error occurred – Oleksii Nov 22 '22 at 22:02
  • I'm not familiar with Mirror itself - I only knew UNet when it was still a thing. There at least you couldn't send any Command or RPCs through objects that weren't owned by your local player -> You always needed the local client authority over an object in order to send Cmd or RPC though it => Usually in order to interact with anything you always had to channel all those Cmd and RPCs through the local player and then route it back to the actual target objects in the scene – derHugo Nov 23 '22 at 04:08
  • So - A) The manger needs to find the local player and trigger the Cmd -> B) Cmd is invoked on the server for this player -> C) player triggers according stuff in the server instance of the manager -> D) Manager again goes through the server's local player and sends RPCs to everyone -> E) everyones according player instance again forwards the resulting RPC to their according local manager instances – derHugo Nov 23 '22 at 04:10

0 Answers0