CodeSmile AssetDatabase 1.9
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches

◆ MainObject

Object MainObject
getset

Gets or sets the asset's main object.

To cast the main object to a specific type you may simply cast the asset:

var myObj = (MyType)asset;

Is short for:

var myObj = (MyType)asset.MainObject;

The same works with the 'as' operator:

var myObj = asset as MyType;

Is short for:

var myObj = asset.MainObject as MyType;

Lastly you can also use the generic getter:

var myObj = asset.Get<MyType>();
See also

Definition at line 35 of file Asset.Properties.cs.

36 {
37 // This 'loads' the asset but most of the time simply returns the internally cached instance.
38 // We need to load the instance because the user may have called static SubAsset.SetMain().
39 get => m_MainObject = LoadMain<Object>();
40 set
41 {
42 SubAsset.SetMain(value, m_AssetPath);
43 m_MainObject = value;
44 }
45 }