Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by LW · Feb 04, 2017 at 12:57 AM · c#assetdatabaseprefabutilitydestroyimmediate

Does UnityEngine.Object.DestroyImmediate() invoke PrefabUtility.PrefabInstanceUpdated?

Hi All,

Does UnityEngine.Object.DestroyImmediate(*someObject*, true) invoke the PrefabUtility.PrefabInstanceUpdated MulticastDelegate?

Thanks,

Lee

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aditya007 · Feb 04, 2017 at 05:36 AM 0
Share

This is the actual DestroyImmediate functions code

 /// <summary>
 ///   <para>Destroys the object obj immediately.</para>
 /// </summary>
 /// <param name="obj">Object to be destroyed.</param>
 /// <param name="allowDestroyingAssets">Set to true to allow assets to be destoyed.</param>
 [$$anonymous$$ethodImpl($$anonymous$$ethodImplOptions.InternalCall)]
 public static extern void DestroyImmediate(Object obj, [DefaultValue("false")] bool allowDestroyingAssets);

There doesn't seem to be any call to PrefabUtility.PrefabInstanceUpdated.

avatar image Bunny83 aditya007 · Feb 04, 2017 at 05:50 AM 0
Share

That conclusion makes no sense. DestroyImmediate is an "extern" method, so it's code is defined in the native part of the editor. We can not know what exactly happens over there.

However the question is not really clear what "someObject" actually is. "PrefabUtility.PrefabInstanceUpdated" is usually called when you apply changes to the actual prefab. Destroying an instance of a prefab does not update / change the prefab and therefore the callback won't be called. If "someObject" is the actual prefab, it might be executed but i actually doubt it.

avatar image aditya007 Bunny83 · Feb 04, 2017 at 06:46 AM 0
Share

Sorry, I kind of new my conclusion didn't make much sense. But, as you say, it is an "extern" method and we don't know what's in there. So, there's no way of knowing whether PrefabUtility.PrefabInstanceUpdated is called from inside DestroyImmediate or not.

Show more comments
avatar image LW aditya007 · Feb 04, 2017 at 03:54 PM 0
Share

Hi @aditya007! I can't see the function body so I can't really be certain whether or not it invokes the PrefabInstanceUpdated delegate. However, even if it doesn't there isn't a guarantee that event doesn't spawn the update in another part of the editor. Does that make sense or am I talking out of my a$$?

avatar image Bunny83 · Feb 04, 2017 at 04:15 PM 0
Share

I haven't really used the PrefabInstanceUpdated delegate (and i'm sure 99.9% of all Unity developers haven't either). I do a lot editor scripting, but i don't work that much with prefabs. I do alot things procedurally ^^.

By a quick google and looking at some usecases, it seems that PrefabInstanceUpdated takes a prefab instance as parameter. The instance where you pressed "apply" on. So removing the prefab itself just breaks the prefab connection. If Unity would call PrefabInstanceUpdated it would need to call it for every instance of that prefab, which doesn't make any sense.

It's still not clear what actual problem you try to solve. If you want to get a callback when a prefab is destroyed, use an Asset$$anonymous$$odificationProcessor. You can also use an AssetPostprocessor, though that callback is called after the asset has been deleted, so at this point it's already gone. It's useful to clean up some internal state of your scripts when an asset got deleted.

avatar image LW Bunny83 · Feb 04, 2017 at 06:12 PM 0
Share

Again, sorry for the lack of clarity @Bunny83. I'm adding ScriptableObject assets as sub-assets of a prefab... I know, don't say it. You ever start trying to solve something and refuse to give up until you get it to work even when it's a bad idea? I think that's my superpower....

As I cannot find a suitable way to remove the subassets (`DestroyImmediate(subAssetObject, true);` doesn't remove the subasset) I was hoping to replace the prefab (also didn't work) and ended up destroying the prefab asset, recreating it, and then rebuilding it from the ground up (also, doesn't remove the subassets).

I'm getting the delegate call on all instances and when I check:

 if (((GameObject)PrefabUtility.GetPrefabParent(instance) == instance) 
 {
 Debug.Log("Oh snap!");
 }

... I see "Oh snap!" print to the ter$$anonymous$$al making me think it's invoked on the prefab as well.

Thank you for pointing me toward Asset$$anonymous$$odificationProcessor it looks like it will solve my problem.

Sincerely,

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

283 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Custom assets give Missing (Mono Script) 0 Answers

Can I save a ScriptableObject holding data from a private database class without [SerializeField]? 1 Answer

Calling all Assetdatabase experts 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges