Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

it is deleting the game object instead of deleting its clone

I’m not exactly sure what I’m doing wrong here. The results I want is clone the game object set it active then delete game Object clone. But instead, It’s it deleting the game Object base which is stopping from happening again.

if (AttackChoice == 2)
{
    MaxedOut();
    gameObject.GetComponentInChildren<Renderer>().material.color = Color.white;
     var clone = Instantiate(Pt, portalSpawn.position, Quaternion.identity);
    _clones.Add(clone);
    clone.transform.parent = null;
    Pt.gameObject.SetActive(true);
    yield return new WaitForSeconds(10);
    
    Destroy(clone);
    gameObject.GetComponentInChildren<Renderer>().material.color = originalColor;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You say

The results I want is clone the game object set it active then delete game Object clone

and you clone the GameObject Pt:

var clone = Instantiate(Pt, portalSpawn.position, Quaternion.identity);

but then you don’t set it active, you set Pt active instead:

Pt.gameObject.SetActive(true);

and then later you destroy the clone:

Destroy(clone);

Your question is poorly worded so I can’t tell what exactly the issue is here. It sounds like you think you’re deleting Pt, the source for the clone instantiation, which is preventing you from re-running the instantiation code (because it’s null), but you are NOT destroying Pt in the snippet you’ve provided.

You are adding the clone to a _clones list, which makes me think you’re doing something else, and I’m wondering if the scripts that are living on the Pt GameObject are somehow triggering the object to self-destruct. In that case, just active the correct object by:

clone.gameObject.SetActive(true);

instead of activating the Pt object.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading