#Instantiating and Destroying

1 messages · Page 1 of 1 (latest)

lethal raptor
#
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponent<PlayerMovement>())
        {
            //This next line of code will console log an error until Challenge 3 is complete.
            gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
            Destroy(other.gameObject);
            //Challenge 4:
            var effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
            Destroy(effect, 1f);
        }
    }

I was figuring this is what you mean, but it still is not working...I am storing the instantiate into effect which is local to the function, then trying to destroy it 1 second later.

abstract pewter
#

as long as the current object isnt destroyed before that happens, it should be fine

#

maybe add a debug to see if it ever happens

lethal raptor
#

If it gets stored into effect?

abstract pewter
#

well yea if the code even runs, i dont really know whats not working specifically

lethal raptor
#

Going to be a couple of messages to show before, during and debug

#

Before Run:

#

During Run:

#

Debug:
FX_Fireworks_Blue_Small (Clone) (UnityEngine.ParticleSystem)
UnityEngine.Debug:Log (object)
FinishPad:OnTriggerEnter (UnityEngine.Collider) (at Assets/Scripts/FinishPad.cs:34)

abstract pewter
#

and its never being destroyed?

lethal raptor
#

so it still never deletes the clone ever nah

abstract pewter
#

is the script or object that spawns the particles being destroyed?

lethal raptor
#

this is assigned on FinishPad which is never destroyed...the player is, but not the finishpad

abstract pewter
#

can you do this and see if its ever destroyed then? i really would just assume the script is being destroyed

    IEnumerator DestroyParticles(INSERTTYPE obj, float delay)
    {
        yield return new WaitForSeconds(delay);
        Debug.Log("Destroying");
        Destroy(obj);
    }
#

unless you are instantiating the object twice, once somewhere else

lethal raptor
#

Where do you want that? Just at the bottom?

abstract pewter
#

because at least you can see the debug happen when its supposed to destroy. If you see "Destroying" then that means u are just instantiating 2 of the objects

lethal raptor
#

it doesnt like the inserttypew

#

sorry...I am really new and trying to figure it out as well

abstract pewter
lethal raptor
#
private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponent<PlayerMovement>())
        {
            var effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
            StartCoroutine(effect, 2);
            //This next line of code will console log an error until Challenge 3 is complete.
            gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
            Destroy(other.gameObject);
            //Challenge 4:
        }
    }
    IEnumerator DestroyParticles(INSERTTYPE obj, float delay)
    {
        yield return new WaitForSeconds(delay);
        Debug.Log("Destroying");
        Destroy(obj);
    }

I figure I have to pass the two arguments of the obj name and the amount of time I want

abstract pewter
#

i didnt know what the data type of the object is so i just wrote INSERTTTYPE to tell you to insert it

#

StartCoroutine(DestroyParticles(effect, 2));
then change INSERTTYPE to the type the object is. i believe its a game object right?

lethal raptor
#

ParticleSystem

abstract pewter
#

huh can you show what you put there

lethal raptor
#
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponent<PlayerMovement>())
        {
            ParticleSystem effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
            StartCoroutine(effect, 2);
            //This next line of code will console log an error until Challenge 3 is complete.
            gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
            Destroy(other.gameObject);
            //Challenge 4:
        }
    }
    IEnumerator DestroyParticles(ParticleSystem obj, float delay)
    {
        yield return new WaitForSeconds(delay);
        Debug.Log("Destroying");
        Destroy(obj);
    }
}
lethal raptor
#

duh

#

I didnt call the actual method...is that the right term?

#

Destroying
UnityEngine.Debug:Log (object)
FinishPad/<DestroyParticles>d__6:MoveNext () (at Assets/Scripts/FinishPad.cs:39)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

#

but never destroyed

abstract pewter
#

then you are spawning 2 i assume

lethal raptor
#

I dont see two though

#

would it help if I do an OBS cap?

abstract pewter
#

just curious, does the particle system not stop?

#

or is the issue just that the gameobject is in the scene

#

you can destroy the obj.gameObject if you want to destroy the entire object

lethal raptor
#

that is probably what it is

#

its a short clip...like 3 seconds so it does stop playing

#

but I figure its good form to remove items not needed

#

so that worked

#

which means I can probably call effect.gameObject without the coroutine

#
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponent<PlayerMovement>())
        {
            //This next line of code will console log an error until Challenge 3 is complete.
            gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
            Destroy(other.gameObject);
            //Challenge 4:
            ParticleSystem effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
            Destroy(effect.gameObject, 2f);
        }
    }

Final code that worked

#

so before it was destroying it, however it was only destroying the component ParticleSystem

abstract pewter
#

yea i thought u initially meant the particles were still going

#

i shouldve asked more specifics