playMaker

Author Topic: want to respawn/destroy object [SOLVED]  (Read 6857 times)

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
want to respawn/destroy object [SOLVED]
« on: February 02, 2013, 10:02:25 AM »
I have food that the player can move around. When it gets w/in a certain distance of a dino, the dino eats it and the food object is destroyed.

What I want to happen is that after a set amount of time the food respawns and can be fed (destroyed) to the dino all over again. The problem is it seems as if I can only spawn the food obj effectively if it's a prefab and I can only destroy it if it isn't a prefab (I get a warning about not enabling the destruction of assets).

I don't know how to specify that I only want to destroy the instance (clone). I tried specifying the instance as an obj variable and then specifying the destruction of that. However, unless I overlooked smthg, that didn't seem to work.

Halp!
« Last Edit: February 05, 2013, 02:29:14 PM by mikejkelley »

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: want to respawn/destroy object
« Reply #1 on: February 02, 2013, 10:24:37 AM »
in your scenario you would definitely not want to destroy the gameObject. Instead use activateGameObject to disable the fruit once it's eaten. This will make it virtually free (performancewise) but once you want to respawn it you'll just have to activate it again. Unity has a very hard time creating new gameObjects/ it's very expensive, so you should definitely do this to prevent any hickups, even on small objects.
Best,
Sven

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: want to respawn/destroy object
« Reply #2 on: February 02, 2013, 01:15:00 PM »
Hm, Ok I'll try that thanks! :)

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: want to respawn/destroy object
« Reply #3 on: February 02, 2013, 05:14:55 PM »
Does Activate have any other properties or does it just set render mesh false? The help listing on it was obtuse.

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: want to respawn/destroy object
« Reply #4 on: February 03, 2013, 04:11:54 AM »
it is like a main switch for all the components on the gameObject. If it's deactivated, it's the same as if it wouldn't exist for the game (well, except that you can still access it) . So the mesh is free, the collider is free and if there are any FSMs on it, those are free as well. It does not reset the position though. Nor does it reset script attributes, so you have to make sure that if you use scripts or FSMs, you set your variables to certain default values in the start state or start function.

Maybe it helps to know that this is the secret behing those famed pool systems (like PoolManager etc). They make it look fancy, but effectively they are just creating a bunch of gameObjects (can be thousands) right on startup and then they deactivate them all. Then, later when you need them, they activate them again.
Best,
Sven

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: want to respawn/destroy object [SOLVED]
« Reply #5 on: February 05, 2013, 02:28:47 PM »
I see, cool thnx. I was confused bcs the dino was still able to "sense" the deactivated food and would go over and eat it so I solved that w/ an accompanying global boolean. Thnx again.