Class Prefab
Json asset that stores the collection of scene objects including actors and scripts. In general, it can serve as any grouping of scene objects (for example a level) or be used as a form of a template instantiated and reused throughout the scene.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Level/Prefabs/Prefab.h
Syntax
public class Prefab : public JsonAssetBase
Fields
NestedPrefabs
The prefab assets ids contained within the prefab asset. Valid only if asset is loaded. Remember that each nested prefab can contain deeper references to the other assets.
Declaration
public Array<Guid> NestedPrefabs
Field Value
Array<Guid>
|
ObjectsCache
The objects cache maps the id of the object contained in the prefab asset (actor or script) to the default instance deserialized from prefab data. Valid only if asset is loaded and GetDefaultInstance was called.
Declaration
public Dictionary<Guid, SceneObject* > ObjectsCache
Field Value
Dictionary<Guid, SceneObject >
|
ObjectsCount
The serialized scene objects amount (actors and scripts).
Declaration
public int32 ObjectsCount
Field Value
int32
|
ObjectsDataCache
The objects data cache maps the id of the object contained in the prefab asset (actor or script) to the json data node for its data. Valid only if asset is loaded.
Declaration
public Dictionary<Guid, ISerializable::DeserializeStream* > ObjectsDataCache
Field Value
Dictionary<Guid, ISerializable::DeserializeStream >
|
ObjectsHierarchyCache
The object hierarchy cache that maps the PrefabObjectID into the list of children (identified also by PrefabObjectID). Objects without any children are not included for sake of optimization. Used for quick validation of the structure of loaded prefab instances. Valid only if asset is loaded.
Declaration
public Dictionary<Guid, Array<Guid>> ObjectsHierarchyCache
Field Value
Dictionary<Guid, Array<Guid>>
|
ObjectsIds
The objects ids contained within the prefab asset. Valid only if asset is loaded.
Declaration
public Array<Guid> ObjectsIds
Field Value
Array<Guid>
|
Methods
ApplyAll(Actor* targetActor)
Applies the difference from the prefab object instance, saves the changes and synchronizes them with the active instances of the prefab asset.
Applies all the changes from not only the given actor instance but all actors created within that prefab instance.
Declaration
public bool ApplyAll(Actor* targetActor)
Parameters
Actor
targetActor
The root actor of spawned prefab instance to use as modified changes sources. |
Returns
bool
True if failed, otherwise false. |
GetDefaultInstance()
Requests the default prefab object instance. Deserializes the prefab objects from the asset. Skips if already done.
Declaration
public Actor* GetDefaultInstance()
Returns
Actor
The root of the prefab object loaded from the prefab. Contains the default values. It's not added to gameplay but deserialized with postLoad and init event fired. |
GetDefaultInstance(const Guid& objectId)
Requests the default prefab object instance. Deserializes the prefab objects from the asset. Skips if already done.
Declaration
public SceneObject* GetDefaultInstance(const Guid& objectId)
Parameters
Guid
objectId
The ID of the object to get from prefab default object. It can be one of the child-actors or any script that exists in the prefab. Methods returns root if id is empty. |
Returns
SceneObject
The object of the prefab loaded from the prefab. Contains the default values. It's not added to gameplay but deserialized with postLoad and init event fired. |
GetNestedObject(const Guid& objectId, Guid& outPrefabId, Guid& outObjectId)
Gets the reference to the other nested prefab for a specific prefab object.
Declaration
public bool GetNestedObject(const Guid& objectId, Guid& outPrefabId, Guid& outObjectId) const
Parameters
Guid
objectId
The ID of the object in this prefab. |
Guid
outPrefabId
Result ID of the prefab asset referenced by the given object. |
Guid
outObjectId
Result ID of the prefab object referenced by the given object. |
Returns
bool
True if got valid reference, otherwise false. |
GetRootObjectId()
Gets the root object identifier (prefab object ID). Asset must be loaded.
Declaration
public Guid GetRootObjectId() const
Returns
Guid
|
loadAsset()
Loads asset
Declaration
protected virtual LoadResult loadAsset() override
Returns
LoadResult
Loading result |
Overrides
Resave()
Resaves the prefab asset to the file by serializing default instance in the latest format and defaults.
Declaration
public bool Resave()
Returns
bool
True if failed, otherwise false. |
unload(bool isReloading)
Unloads asset data
Declaration
protected virtual void unload(bool isReloading) override
Parameters
bool
isReloading
True if asset is reloading data, otherwise false. |