playMaker

Author Topic: Can't remove scene object?[SOLVED]  (Read 5237 times)

mathius777

  • Playmaker Newbie
  • *
  • Posts: 38
Can't remove scene object?[SOLVED]
« on: February 17, 2014, 04:09:10 PM »
Whenever I call the PM action " Destroy Object", I get the following exception:

Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);


I am adding a quest prefab to a scene, and after the quest finishes, I wan't to remove it, so I was storing the loaded quest in a global prefab from a script. I am dynamically adding the prefab in c# code, so the ONLY way PM can know what prefab I loaded is if I store the loaded quest prefab in  a global variable(or is there another way?). I am getting the exception because I am trying to delete the global variable I guess?

All I am trying to do is delete the dynamically loaded prefab after I am done with it. How would I do this? Thanks.

« Last Edit: February 17, 2014, 11:51:32 PM by jeanfabre »

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Can't remove scene object?
« Reply #1 on: February 17, 2014, 04:23:40 PM »
What's happening is you are telling Playmaker to delete the pre fab and Playmaker is throwing you a warning that hey we shouldn't do that. What you want is a reference to the gameobject in the scene that is a prefab. You can do that by using the "Get Owner" action and storing it in a Gameobject variable and then when you call destroy you need to use that variable so Playmaker knows to destroy the prefab in the scene and not the prefab in the project directory.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Can't remove scene object?
« Reply #2 on: February 17, 2014, 04:25:23 PM »
You get that error if you try to destroy a prefab asset. You need to destroy the instance of that prefab in the scene.

The easiest solution is probably to have the Quest destroy itself when it's finished. Use the Destroy Self action.

Otherwise you need a references to the prefab instance in the scene. You can store a reference when you use Create Object. Or you can find it later using Find Game Object (by name or tag).

mathius777

  • Playmaker Newbie
  • *
  • Posts: 38
Re: Can't remove scene object?
« Reply #3 on: February 17, 2014, 04:56:00 PM »
Thanks a lot. I fixed it. Just had to save the object returned from GameObject.Instantiate(). Thanks!