class Prefab

Inherits: Resource

Prefab is a saveable hierarchy of scene objects.

It can be instanced, and instances will maintain a link to the original prefab they were created from, allowing you to update them to latest version if the prefab changes. Prefabs can also be nested within each-other, as long as there are no circular dependencies. Instanced prefabs can also contain per instance modifications that will be preserved even if the prefab they were created from changes.

Public

Constructors

Prefab

Prefab()

Methods

~Prefab

~Prefab() noexcept

Instantiate

HSceneObject Instantiate(const SPtr<SceneInstance> &sceneInstance) const

Instantiates a prefab by creating an instance of the prefab's scene object hierarchy.

The returned hierarchy will be parented to the provided scene instance root.

sceneInstance
Scene instance into which to instantiate the prefab instance in.

Returns: Instantiated clone of the prefab's scene object hierarchy.

GetPrefabVersion

UUID GetPrefabVersion() const

Returns a version value that gets updated every time the prefab contents update.

Can be used for detecting if a prefab instance is up to date.

AllowAsyncLoading

bool AllowAsyncLoading() const override

Returns whether or not this resource is allowed to be asynchronously loaded.

staticCreate

static HPrefab Create(const HSceneObject &sceneObject)

Creates a new prefab from the provided scene object.

If the scene object has an existing prefab link it will be broken. After the prefab is created the scene object will be automatically linked to it.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

Internal

Methods

GetRoot

HSceneObject GetRoot() const

Returns a reference to the internal prefab hierarchy.

Returned hierarchy is not instantiated and cannot be interacted with in a manner you would with normal scene objects.

GetGameObjectCollection

SPtr<GameObjectCollection> GetGameObjectCollection() const

Returns the game object collection that owns all the game objects in the prefab.

Clone

HSceneObject Clone(const SPtr<GameObjectCollection> &cloneOwnerCollection) const

Creates the clone of the prefab's current hierarchy but doesn't instantiate it.

cloneOwnerCollection
Collection into which to place the cloned scene objects. If is true this must be a different collection that the prefab's internal collection, otherwise IDs would conflict.

Returns: Clone of the prefab's scene object hierarchy.

InstantiateAsScene

SPtr<SceneInstance> InstantiateAsScene() const

Instantiates a prefab by creating an instance of the prefab's scene object hierarchy as a brand new scene instance, whose root is the prefab root.

Returns: Newly created scene instance.

ReplaceInternalHierarchy

UnorderedMap<UUID, UUID> ReplaceInternalHierarchy(const HSceneObject &sceneObject)

Replaces the contents of this prefab with new contents from the provided object.

Returns a map of IDs that were remapped to new IDs within the prefab.

TickPrefabVersion

void TickPrefabVersion()

Updates the internal prefab version to a new value.

You should call this after modifying the prefab hierarchy.

RecordNestedPrefabInstanceDeltas

void RecordNestedPrefabInstanceDeltas()

Updates deltas for any nested prefab instances.

Private

Methods

staticCreateEmpty

static SPtr<Prefab> CreateEmpty()

Creates an empty and uninitialized prefab.

InstantiateInternal

HSceneObject InstantiateInternal(SPtr<SceneInstance> &inOutSceneInstance) const

Instantiates a prefab by creating an instance of the prefab's scene object hierarchy.

The returned hierarchy will be parented to world root by default, if the provided instance is non-empty. If the provided scene instance is empty, new scene instance will be created and prefab's root will be set as the scene instance's root.

inOutSceneInstance
Scene instance into which to instantiate the prefab instance in. If null, new scene instance will be created and output through this parameter.

Returns: Instantiated clone of the prefab's scene object hierarchy.

Initialize

void Initialize() override

Initializes all the internal data of this object.

Must be called right after construction for new objects, or after deserialization for deserialized objects. If requested, render proxy is created and queued for initialization on the render thread.

Destroy

void Destroy() override

Frees all the data held by this object.

If the object has a render proxy, the internal reference to the render proxy will be released, but the proxy will not be destroyed unless this was the last reference. If render proxy destruction does happen, it is not immediate, but rather queued for destruction on the render thread.

Fields

mRoot

HSceneObject mRoot

mPrefabVersion

UUID mPrefabVersion

mUUID

UUID mUUID

mGameObjectCollection

SPtr<GameObjectCollection> mGameObjectCollection

Collection owning the internal hierarchy.