Search Unity

Destroying assets is not permitted to avoid data loss

Discussion in 'Visual Scripting' started by Norm49, Jun 15, 2021.

  1. Norm49

    Norm49

    Joined:
    Jun 7, 2021
    Posts:
    12
    Hi I always have this message (Destroying assets is not permitted to avoid data loss) when I try to destroy a item on the ground after the player pick it up. I try doing this on the object it self and form the inventory visual script. I out of idea I been on dis for 2 days.

    I can i do it? Thanks.
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,068
    Make sure you're using "GameObject.Destroy" and not some other Destroy related node such as "Object.DestroyImmediate". Also make sure you're destroying the instantiated object in the scene and NOT its prefab template from Project Window.
     
    Last edited: Jun 15, 2021
  3. Norm49

    Norm49

    Joined:
    Jun 7, 2021
    Posts:
    12
    I think my problem is my Visual script is not calling the instantiated object. How can I do that?
     
  4. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    If your visual script is instantiating the object, you can fetch a reference to that instance when it is instantiated. That is the return value of the instantiate function/node
     
    Last edited: Jun 15, 2021
  5. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,068
    As Hikiko66 mentioned, GameObject.Instantiate has an output that references the instantiated object. You can then cache that output of the instantiated GameObject in a variable for use later. Likely GameObject or Scene variable.

    If you've placed the GameObject you want to destroy in the scene by hand and it exists in Hierarchy window before entering Play mode then you can manually create either a GameObject variable or scene variable referencing that object. Then use Get Variable node to get the GameObject for Destroy node.