Search Unity

Other Destroying Assets is Not Permitted Error. (HELP NEEDED)

Discussion in 'Scripting' started by nirmaljake, Oct 29, 2022.

  1. nirmaljake

    nirmaljake

    Joined:
    Jul 15, 2020
    Posts:
    59
    upload_2022-10-29_14-30-3.png
    This is my code, I don't understand why that error is coming please tell me what is wrong with my code and how do I fix it. Thanks in advance.
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,648
    You're trying to destroy a prefab. You want to destroy the copy of the object you cloned instead.
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    var instancedParticleSystem = Instantiate(..);

    then destroy the instanced system. Pass it into the method call. Btw you should rather use a coroutine than Invoke.
     
  4. nirmaljake

    nirmaljake

    Joined:
    Jul 15, 2020
    Posts:
    59
    Sorry to disturb but can you please write and send the code, I am having so many casualties. It would be nice if you sent it thanks in advance.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Go back and read what Code and Red wrote.

    Your Destroy() is destroying the prefab.

    You CANNOT do that. That is the error.

    Instead, keep a reference (in another variable) to what Instantiate() returns, which will be the ACTUAL particles created out of the prefab.

    Destroy THAT object when you want it gone, leaving the prefab alone.