diff --git a/Source/Engine/Content/JsonAsset.cs b/Source/Engine/Content/JsonAsset.cs index 15ff3cd4d..a3f10b646 100644 --- a/Source/Engine/Content/JsonAsset.cs +++ b/Source/Engine/Content/JsonAsset.cs @@ -14,6 +14,17 @@ namespace FlaxEngine /// public object Instance => _instance ?? (_instance = CreateInstance()); + /// + /// Gets the instance of the serialized object from the json data. Cached internally. + /// + /// The asset instance object or null. + public T GetInstance() + { + if (Instance is T instance) + return instance; + return default; + } + /// /// Creates a new instance of the serialized object from the json asset data. /// diff --git a/Source/Engine/Content/JsonAssetReference.cs b/Source/Engine/Content/JsonAssetReference.cs index bec0cedf7..a3a17fe2b 100644 --- a/Source/Engine/Content/JsonAssetReference.cs +++ b/Source/Engine/Content/JsonAssetReference.cs @@ -33,6 +33,15 @@ namespace FlaxEngine Asset = asset; } + /// + /// Gets the deserialized native object instance of the given type. Returns null if asset is not loaded or loaded object has different type. + /// + /// The asset instance object or null. + public U GetInstance() + { + return Asset ? Asset.GetInstance() : default(U); + } + /// /// Implicit cast operator. ///