- Home /
How to, tell apart, Instance or Instantiated GameObject vs Loaded GameObject.
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.
However.
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
#if UNITY_5
return resultAssetBundle .LoadAssetAsync(name, type);
#else
return resultAssetBundle .LoadAsync(name, type);
#endif
//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 :) $$anonymous$$aybe it can help.
Your answer
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object ??? 1 Answer
Can't Instantiate AnimationClip from AssetBundle correctly 1 Answer
NullReference Exception when adding a class 2 Answers
Loading prefabs with script references from assetbundle 0 Answers
How do I instantiate the contents of an asset bundle multiple times? 1 Answer