unity – Shopper error I can not spawn canvas and asign it to my consumer participant -Netcode for Gameobjects

unity – Shopper error I can not spawn canvas and asign it to my consumer participant -Netcode for Gameobjects

[ad_1]

in my netcode unity c# code I’ve a bunch and a consumer, and every time i attempt to instantiate a consumer I get this error regardless that canvasInstance isn’t null because it’s passing the debug

public class PlayerNetworkConfigurer : NetworkBehaviour
{
    [SerializeField] non-public GameObject canvasPrefab;
    [SerializeField] non-public PlayerStatusModel statusModel;
    [SerializeField] non-public Participant playerScript;
    GameObject canvasInstance;

    public override void OnNetworkSpawn()
    {
        if (IsOwner)
        {
            // Instantiate the canvas prefab just for the proprietor
            canvasInstance = Instantiate(canvasPrefab);
            if (canvasInstance == null) Debug.Log("o que deu?");
            //canvasInstance.GetComponent<NetworkObject>().Spawn(true);


            if (IsClient)
            {
                Debug.Log("é pra ser cliente né?");
                SpawnCanvasServerRpc();
              
            }
            else 
            {
                Debug.Log("aaa");
                SpawnCanvas(); 


            }
            if (canvasInstance == null)  Debug.Log("oxxx que deu?");

            // Set the canvas guardian to this object (proprietor)

            // Set the native place to zero to maintain it relative to the proprietor
            canvasInstance.rework.localPosition = Vector3.zero;

            // Make certain the canvas is seen and interactable just for the proprietor


            canvasInstance.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceCamera;

            //canvasInstance.GetComponent<Canvas>().worldCamera = Digital camera.important;
            canvasInstance.SetActive(true);
            SetStatusImages(canvasInstance);
            playerScript.InventoryManager = canvasInstance.GetComponent<InventoryManager>();

            Rework capule = FindChildByName(rework, "Capsule");
            Rework hand = FindChildByName(capule, "Hand");
            playerScript.InventoryManager.HandParent  = hand;
            Rework InventoryUI1 = FindChildByName(canvasInstance.rework, "InventoryUI1");

            playerScript.InteractionText = FindChildByName(InventoryUI1, "InteractionText").gameObject.GetComponent<TextMeshProUGUI>();
        }
    }
    non-public void SpawnCanvas()
    {
        NetworkTransform networkTransform;
        networkTransform = GetComponent<NetworkTransform>();
        Debug.Log((rework.gameObject.identify));
        Debug.Log((rework.GetComponent<NetworkObject>().NetworkObjectId));

        Debug.Log(networkTransform.NetworkObject.OwnerClientId);
        canvasInstance.GetComponent<NetworkObject>().SpawnWithOwnership(networkTransform.NetworkObject.OwnerClientId);
        canvasInstance.rework.SetParent(networkTransform.gameObject.rework);
    }
    [ServerRpc(RequireOwnership = false)]
    non-public void SpawnCanvasServerRpc()
    {
        SpawnCanvas();
        Debug.Log("é ");
    }



NullReferenceException: Object reference not set to an occasion of an object
PlayerNetworkConfigurer.SpawnCanvas () (at Property/Scripts/Community/PlayerNetworkConfigurer.cs:74)
PlayerNetworkConfigurer.SpawnCanvasServerRpc () (at Property/Scripts/Community/PlayerNetworkConfigurer.cs:80)
PlayerNetworkConfigurer.__rpc_handler_1989096977 (Unity.Netcode.NetworkBehaviour goal, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) (at <05a5223dbd3d4bec92736c6fbf2e0a1b>:0)
Unity.Netcode.RpcMessageHelpers.Deal with (Unity.Netcode.NetworkContext& context, Unity.Netcode.RpcMetadata& metadata, Unity.Netcode.FastBufferReader& payload, Unity.Netcode.__RpcParams& rpcParams) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/Messages/RpcMessages.cs:70)
Rethrow as Exception: Unhandled RPC exception!
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.RpcMessageHelpers:Deal with(NetworkContext&, RpcMetadata&, FastBufferReader&, __RpcParams&) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/Messages/RpcMessages.cs:74)
Unity.Netcode.ServerRpcMessage:Deal with(NetworkContext&) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/Messages/RpcMessages.cs:125)
Unity.Netcode.NetworkMessageManager:ReceiveMessage(FastBufferReader, NetworkContext&, NetworkMessageManager) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/NetworkMessageManager.cs:570)
Unity.Netcode.NetworkMessageManager:HandleMessage(NetworkMessageHeader&, FastBufferReader, UInt64, Single, Int32) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/NetworkMessageManager.cs:434)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue() (at ./Library/PackageCache/[email protected]/Runtime/Messaging/NetworkMessageManager.cs:460)
Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkManager.cs:45)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:185)
Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:208)

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply