playMaker

Author Topic: Destroy clone game object.  (Read 3551 times)

Aaddiction

  • Full Member
  • ***
  • Posts: 166
Destroy clone game object.
« on: April 18, 2016, 08:58:52 AM »
I spawn a game object in the scene from a prefab and store it in a Game Object global var. When I try to destroy the instantiated game object I cannot, because the Game Object variable is storing the prefab in the project, not the instantiated prefab in the scene.

How to destroy the Object in the scene and not the prefab, for which I get an error that it cannot be done, because I'd lose the asset in the project?

Thanks!

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: Destroy clone game object.
« Reply #1 on: April 18, 2016, 09:45:42 AM »
you set the variable to the instance, instead of the prefab
if you're using the Create Object action, use Store Object

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: Destroy clone game object.
« Reply #2 on: April 18, 2016, 09:56:35 AM »
Hi,

I assume youre using the create object action to spawn.

Well there is a box there that says 'store object'.

Create a game object variable in the variable tab and select it in the 'store object' box.

This will save the created game object into that variable.

Then when you want to destroy that gameobject that you just created, in the 'destroy object' action chose the variable you stored into as the game object to destroy.

If you want to destroy it from a different fsm than the one that created it; use global variables. You can also use such actions as 'set/get fsm gameobject' instead of global variables and there are other ways.

Good luck hope this helps.

(edit to add: Hi terri, I didnt see you there. But yeah, nice to see that someone else confirms it, as im just a noob)
« Last Edit: April 18, 2016, 09:58:25 AM by Zeldag »

Aaddiction

  • Full Member
  • ***
  • Posts: 166
Re: Destroy clone game object.
« Reply #3 on: April 18, 2016, 10:55:27 AM »
Thank you! That's it!  ;D