Hi
I have a CustomEditor script which calls a method on a MonoBehaviour script. This method gets called while in edit mode only so the game is not running yet. Inside this method I'm trying to get access to a combatant settings (its default prefab). I thought I could use the value of ORK.Combatants.Get(orkID).prefab.prefab but it's an AssetSource. However I need the GameObject to run GetComponent<>() on it.
I'm pretty sure there is a way to access the Combatant's prefab GameObject outside of the Play mode but can't figure how :-(
GameObject prefab = ORK.Combatants.Get(index).prefab.prefab.StoredAsset;
AssetSource is a wrapper for the asset selection system (reference, asset bundle, etc.), accessing the StoredAsset will get you the asset itself. Naturally, this'll return null if no asset was selected yet.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
AssetSource' does not contain a definition for 'StoredAsset' and no accessible extension method ....
Should I add a using directive ? Just to make sure, we are on ORK2
GameObject prefab = ORK.Combatants.Get(index).prefab.prefab;
The code has automatic casting capabilities to handle that for you :)
ORK 3's StoredAsset is just a bit better for performance as it doesn't need to do some checks and loads each time.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
It also works event after I hit "Stop". I'm assuming that the database remains loaded untill the gc do it's job ?! Which does not occur event if I hit "Stop".
However, if the game is stopped and then I recompile, the instruction is not working anymore. ORK.Combatants is null. I am assuming that recompiling the project triggers the gc and ORK's database get unloaded from memory. At this point I'm not sure what is going on under the hood.
But one thing I'm sure is that during Play mode or right after I hit "Stop", the instruction ORK.Combatants.Get(index).prefab.prefab works totaly fine. But as soon as it recompile, it failed because ORK.Combatants throw error "System.NullReferenceException:Object reference not set to an instance of an object".
This only works for editor code:
if(!ORK.Instantiated)
{
ORK.Initialize(ORKAssetHelper.LoadORKProject());
}
Otherwise, you can use the same with a provided ORK project asset outside of editor code (e.g. have the asset as a regular asset field in your code):
if(!ORK.Instantiated)
{
ORK.Initialize(projectAsset);
}
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!