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

◆ LoadOrCreate< T >()

static T LoadOrCreate< T > ( [NotNull] Path path,
[NotNull] Func< T > getInstance )
static

Loads an asset at path or creates the asset if needed.

  • If the file does not exist, creates the asset using the object returned from getInstance parameter.
  • If the asset isn't in the database, imports and loads the asset.
Parameters
pathPath to an asset file.
getInstanceMethod that returns an object instance. Invoked only if the asset needs to be created.
Template Parameters
TUnityEngine.Object derived type.
Returns
The loaded or created asset.
See also
Type Constraints
T :Object 

Definition at line 388 of file Asset.File.cs.

388 : Object
389 {
390 if (path.ExistsInFileSystem == false)
391 return Create(getInstance.Invoke(), path) as T;
392
393 return ImportAndLoad<T>(path);
394 }
static T ImportAndLoad< T >([NotNull] Path path, ImportAssetOptions options=ImportAssetOptions.Default)
Imports a file at a given path that was created or modified 'externally', then loads and returns the ...
static Object Create([NotNull] Byte[] contents, [NotNull] Path path)
Writes the byte array to disk, then imports and loads the asset. Overwrites any existing file.

References Asset.File.Create(), and Asset.File.ImportAndLoad< T >().

+ Here is the call graph for this function: