Context: We have a field of type GameObject called "obj" (example). It can hold an instance of a gameobject we have in the scene, or a Loaded (No instance) Gameobject from an AssetBundle. For performance reasons we do not want to instantiate the loaded object. I would like to keep it as a Loaded gameobject and only create instances of it when needed.
I need to know how to destroy this thing once I no longer need it. Wether to use Destroy(gameobject) or Unload of an AssetBundle. However there is no information in a GameObject if its an instance or the original Loaded GameObject in memory.
How do yall handle such cases?
Code that loads the GameObject from AssetBundle
//step 1 we load the WWW
var www = WWW.LoadFromCacheOrDownload(bundleFullUrl, version, crc);
//step 2 we draw the asset bundle
var resultAssetBundle = www.assetBundle;
//step 3 we get the request object
return resultAssetBundle .LoadAssetAsync(name, type);
return resultAssetBundle .LoadAsync(name, type);
//step 4 from the request object we get the asset (Object/GameObject)
var asset = assetBundleRequest.asset
Hi, when an object is from a scene, it's GetInstanceID() is a positive number. When instantiated, it gets a negative number. I don't think it's an official feature but it's reliable since a few years :) Maybe it can help.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
86 People are following this question.
Checking if object intersects?
Know when prefab has finished loading after Resources.Load
What variable type is this?
Possible Bug? GameObject.Instantiate copies instance instead of Prefab
Loading Asset Bundle from raw bytes