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]

I assumed this might have been requested already however I couldn’t discover a solution to it so sorry if it has been requested already.

I’m making a VR recreation in Unity utilizing the Hurricane VR Framework. Now I’m attempting to create a list system like Saints & Sinners, with a backpack, however I couldn’t make it work.

I used to be in a position to make it with the intention to seize gadgets and retailer them within the backpack, it is rather straightforward with this framework, the issue is passing these objects to the following scene the place I get this error:

The thing of sort ‘GameObject’ has been destroyed however you’re nonetheless
attempting to entry it.

What I’ve now’s this recreation supervisor:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine.SceneManagement;
utilizing UnityEngine;

public class GameManager : MonoBehaviour
{

    public static GameManager Occasion;
    // Checklist to retailer the article and the tag of the socket the place it was saved
    personal static Checklist<(string, GameObject)> Stock = new Checklist<(string, GameObject)>();
    // Array with the tags of the stock sockets.
    personal string[] tags = { "I11", "I12", "I13", "I21", "I22", "I23", "HolsDer", "HolsIz"}; 

    personal void Awake()
    {

        if(Occasion==null)
        {
            Occasion = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            if(Occasion!=null)
            {
                Destroy(gameObject);
            }
        }
    }
    // Add a brand new tuple to the stock
    public void addObject(string socket, GameObject objeto)
    {
        if (objeto != null)
        {
            Debug.Log(objeto.tag);
            Stock.Add((socket, objeto));
        }
        else
        {
            Debug.Log("Object is null");
        }
    }
    
    public void nextScene(int scene)
    {
        // Iterate by the tags of the sockets to seek out objects within the present scene
        foreach (string tag in tags)
        {
            // Search the sockets by tag
            GameObject[] sockets = GameObject.FindGameObjectsWithTag(tag);
            if (sockets.Size > 0)
            {
                GameObject socket = sockets[0];

                // Test if the socket has a toddler (It all the time has one baby so the situation 
                // is that it should have 2, the default and the article)
                if (socket.rework.childCount == 2)
                {
                    GameObject objeto = socket.rework.GetChild(1).gameObject;
                    DontDestroyOnLoad(objeto);

                    // Add the article to the Stock record
                    addObject(tag, objeto);
                }
                else
                {
                    Debug.Log("No childs in socket "+ tag);
                }
            }
            
        }

        // Load subsequent scene
        SceneManager.LoadScene(scene);
    }
    // That is known as initially of every scene.
    public void restoreObjects()
    {
        foreach ((string socketName, GameObject objeto) in Stock)
        {
            // Discover the socket the place the article needs to be positioned
            GameObject[] sockets = GameObject.FindGameObjectsWithTag(socketName);

            if (sockets.Size > 0)
            {
                GameObject socket = sockets[0];
                // Test for null objects or sockets (That is the place it fails, the objects are all null)
                if(objeto == null)
                {
                    Debug.Log("objeto is null");
                }
                if (socket == null)
                {
                    Debug.Log("Socket is null");

                }
                // This fails throwing this error: The thing of sort 'GameObject' has been destroyed however you're nonetheless attempting to entry it.
                GameObject newObject = Instantiate(objeto, socket.rework);
            }
            else
            {
                Debug.LogWarning("Socket with tag '" + socketName + "' not discovered.");
            }
        }
    }
}

The nextScene() operate is named when urgent a button, only for testing and the restoreObjects() one is named initially of the following scene and that’s when it fails as a result of the article is null.

What am I doing fallacious?

[ad_2]

Leave a Reply

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