List
Need Help Resolving Object Destruction Issue
Posted Date: 2023-08-01 14:51     Edited Date: 2023-08-11 8:56     Writer: augmentablestech

1. SDK Version: 6.0.1
2. Development Environment: (Unity-iOS) Windows 11
3. Tracker/Scanner: Image Tracker
4. License Type(Free / Pro-One Time Fee / Pro-Subscription / Enterprise): Free
5. Target Device(Optional): IPhone / Android

I hope this post finds you well. I am facing a perplexing issue in my Unity project, and after trying various troubleshooting steps, I am still unable to resolve it. I am reaching out to seek the assistance of the Official Team or any experienced members who might have encountered a similar problem and can offer valuable insights.

Issue Description:
In my project, I have a script responsible for spawning and managing objects (meteors) in the scene. The spawning process is supposed to create 20 meteors at different positions, but I can only see one meteor in the Hierarchy when it should have 20. I have carefully reviewed the code, added debug logs, and verified all the logical aspects, but the problem persists.

Troubleshooting Done So Far:
1. Checked the loop logic to ensure it iterates correctly.
2. Confirmed that the `spawnPoint` object has enough children for the loop to execute.
3. Verified that the `meteor` prefab is correctly assigned in the Inspector.
4. Ensured that the parent object "Environment/ImageTrackable" is active and not disabled from view.
5. Added debug logs to check the spawning positions and parentage.
6. Temporarily disabled other scripts/components that could interfere.
7. Discovered through a logging script attached to the meteor object that the meteors are getting spawned and then instantly destroyed.

If you have encountered similar problems in the past or have expertise in Unity scripting and object management, your insights would be highly appreciated. Specifically, I would like to know if there are any specific scenarios or common issues that can lead to immediate object destruction upon spawning.

Moreover, if there are any additional tools or techniques I can use to further investigate this issue, I would be grateful for the guidance.

Code Snippet:
Here's a snippet of the relevant code that handles object spawning:

 

void Update()

    {

        Debug.Log(MeteorSpawnerScript.Instance.gameisRunning);

        if(gameisRunning)

        {

            Debug.Log("Game Running");

            if (activeSpawn < maxSpawn) //This loop makes sure that the game keeps continuing and meteors keep spawning.

            {

                child = (int)Random.Range(0f, 20f);

                GameObject spawn = Instantiate(meteor,spawnPoint.transform.GetChild(child).position,Quaternion.identity);

                spawn.transform.parent = GameObject.Find("Environment/ImageTrackable").transform;

                activeSpawn++;

            }

        }

    }

 

    public void destroyMeteor()

    {

        activeSpawn--;

        scoreScript.Instance.hitMeteor(); //Manages score of the player and destroys the meteor.

        Debug.Log("meteor destroyed");

    }

 

    public void StartGame()

    {

        gameisRunning = true;

        Transform parentTransform = GameObject.Find("Environment/ImageTrackable")?.transform;

        if (parentTransform != null && parentTransform.gameObject.activeSelf)

        {

            for(i=0;i<=20;i++)

            {  

                Debug.Log("meteor spawn " + i + " at position: " + spawnPoint.transform.GetChild(i).position);

                GameObject spawn = Instantiate(meteor,spawnPoint.transform.GetChild(i).position,Quaternion.identity);

                spawn.transform.parent = GameObject.Find("Environment/ImageTrackable").transform;

            }

        }

    }

 

Screenshots:

 

I would be more than willing to share additional code or information upon request to facilitate a better understanding of the issue.

Thank you in advance for any assistance or advice you can provide. I am looking forward to engaging in a constructive discussion with the community.

Best regards,
Augmentables Tech

Posted Date: 2023-08-11 8:56     Edited Date: 2023-08-11 8:56     Writer: sejin

Thank you for your interest in MAXST AR SDK.

Based on the above question, it's hard to answer because we don't know why the GameObject is being destroyed and how it relates to the Maxst AR SDK.


Best regards,

Shelden

MAXST Support Team