Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[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]

Leave a Reply

Your email address will not be published. Required fields are marked *