What are all the "native engine object" types in Unity?

Hi,

Thanks for pointing out this gap in the docs. While we work on fixing that, I’ll try to answer the questions you raised here.

Native Unity Objects means any type that inherits from UnityEngine.Object. Any such type can have a Managed Wrapper/Shell object used to communicate with the native side from a script. That wrapper can get garbage collected, but that won’t cause the destruction of the native Object.

Native Objects can either be

  • loaded in with a scene or associated with it at runtime (i.e. instantiating Game Objects get placed in the currently active scene) and will get unloaded on the second destructive (i.e. non Additive) scene load, or once you call Resources.UnloadUnusedAssets after that scene is unloaded.

  • Made persistent via DontDestroyOnLoad

  • Created with new

  • accessing the .material property (instead of .sharedMaterial)

  • Instantiating ScriptableObjects (or anything but a GameObject, really)

  • Creating Textures/Render Textures and other Asset types

Now, everything but 1. requires custom handling of it’s life time, i.e. you’ll need to call Object.Destroy on it to clean it up.

AddComponent will associated the object the the GameObject you add it too so that’s gonna be the thing it gets unloaded with, or not.

Now the second destructive scene unload thing: Every destructive scene unload, to ensure there’s space to load to and no too old Memory dangling around, triggers a Resources.UnloadUnusedAssets, before unloading, assuming some assets might still be used in the next scene, and unloading them would be wasting resources. You can always call it manually but if you only have one scene, everything that was loaded in with that scene will permanently stay in memory, yes (except for all the on the fly stuff that was instantiated and destroyed obviously).