playMaker

Author Topic: Destroy randomly created objects  (Read 1621 times)

Tobeee

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Destroy randomly created objects
« on: December 21, 2012, 07:15:41 PM »
Hi guys!

I am spawning objects randomly. So I have a "Create Object" action which has a "Random object" variable inside. I'd like to destroy this object after 5 seconds. I tried the "wait" (5 secs) and the "destroy self" action on each of the randomly spawend objects. The problem is that the objects destroy themselves so they can't be spawned any longer. Does anybody know a method on how to destroy a randomly generated object without destroying it's parent?

Thanks
Tobi
« Last Edit: December 22, 2012, 10:49:57 PM by Tobeee »

Tobeee

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: Destroy randomly created objects
« Reply #1 on: December 22, 2012, 11:05:38 PM »
Ideas anybody? Please!

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • View Profile
    • Blog
Re: Destroy randomly created objects
« Reply #2 on: December 23, 2012, 02:10:23 PM »
Sorry can you describe what you want a little better?
Cheers

Tobeee

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: Destroy randomly created objects
« Reply #3 on: December 23, 2012, 05:42:41 PM »
Hi. I'll try ;)

I want to spawn one out of three obejcts randomly once a second. I want these randomly created objects to be deleted after five seconds.

What I did so far is:

Action: "Select Random Game Object" (Inside this action I select three objects from the hierarchy and store the game object in a game object variable.)

Next Action: "Create Object" (Here I select my game object variable and spawn it at a random position.)

Next Action: "Wait" (Here I wait for one second and then go back to the first action)

So after a while I have a lot of randomly created objects. Now I want them to destroy themselves, each after five seconds. I could use the destroy action on the objects inside the hierarchy but then I wouldn't be able to spawn any longer.

Any idea?
Thanks!

David

  • Playmaker Newbie
  • *
  • Posts: 18
    • View Profile
Re: Destroy randomly created objects
« Reply #4 on: December 24, 2012, 01:00:29 AM »
As long as your objects are prefabs, you should be able to do a "destroy self" on instances that doesn't affect the prefabs.

So you have to :

1. Create prefabs for the objects you want to create randomly with an attached script or fsm that does "Wait for 5 sec" "Destroy self"
2. Use the same way so used but choose the prefabs you created in "Select Random Game Object" instead of scene instances (choose them for the Assets tab and not from the Scene tab when you select the objects for "Select Random Game Object" action)

That should solve your problem :)