Skip to content

Engine → Scene

prefab.h

Prefabs: fully materialised instances marked with prefab_instance on the root and prefab_link on every entity. Overrides are computed by diff, not stored; apply, revert and unpack are archive operations. prefab_builder is the type-agnostic way the engine turns a model into a prefab document.

Structs

File Description
entity_diff One difference between a prefab instance and its asset.
prefab_asset The published payload of the conjure.scene.prefab asset type.
prefab_builder::node
prefab_builder::node_component
prefab_diff The differences of one instance.

Classes

File Description
prefab_builder Builds a prefab document node by node without naming any component type: the engine's model converter adds renderer components by registered name.

Enumerations

entity_diff_kind

enum class entity_diff_kind : u8 {
    ADDED,      // an instance entity without a matching prefab entry
    REMOVED,    // a prefab entry without a matching instance entity
    MODIFIED    // components differ (names listed)
};

How an instance entity differs from its prefab entry.

Macros

CONJURE_DECLARE_ASSET_TYPE

CONJURE_DECLARE_ASSET_TYPE(conjure::scene::prefab_asset, "conjure.scene.prefab")

Functions

Public

prefab::apply

[[nodiscard]] CONJURE_API core::result<prefab_document> apply(const scene &source, ecs::entity root);

The instance as a new prefab document: prefab_link guids become entry guids (fresh ones for new entities and for a link guid an earlier entity already used) and the root loses its prefab_instance. NOT_A_PREFAB_INSTANCE.

prefab::build_document

[[nodiscard]] CONJURE_API core::result<prefab_document> build_document( const scene &source, ecs::entity root, std::string_view name );

Captures the subtree as a prefab document (external references become null, single root).

prefab::diff

[[nodiscard]] CONJURE_API core::result<prefab_diff> diff(const scene &source, ecs::entity root);

Compares the instance with its loaded asset entry by entry (matched through prefab_link). NOT_A_PREFAB_INSTANCE, PREFAB_NOT_LOADED.

prefab::instance_root_of

[[nodiscard]] CONJURE_API ecs::entity instance_root_of(const scene &source, ecs::entity entity) noexcept;

The nearest ancestor (the entity included) carrying prefab_instance, or NULL_ENTITY.

prefab::instantiate

[[nodiscard]] CONJURE_API core::result<ecs::entity> instantiate( scene &target, const prefab_asset &asset, const instantiate_options &options = {} );

Instantiates the prefab (every guid regenerated) and returns the root, which carries a prefab_instance bound to the asset; entities without a prefab_link receive their entry's guid.

prefab::instantiate_many

[[nodiscard]] CONJURE_API core::result<void> instantiate_many( scene &target, const prefab_asset &asset, u32 count, const instantiate_options &options, std::span<ecs::entity> outRoots );

count instances in one batch; outRoots receives the roots in order.

prefab::mark_instance

[[nodiscard]] CONJURE_API core::result<void> mark_instance( scene &target, ecs::entity root, assets::asset_ref<prefab_asset> asset );

Marks a subtree as an instance of asset: prefab_instance on the root, prefab_link with the current guid on every entity (guids are generated where missing).

prefab::refresh_instances

[[nodiscard]] CONJURE_API u32 refresh_instances( scene &target, const assets::asset_id &prefab, bool onlyUnmodified = true );

Reverts every instance of the prefab (only the unmodified ones by default). Returns how many were reverted.

prefab::revert

[[nodiscard]] CONJURE_API core::result<void> revert(scene &target, ecs::entity root);

Replaces the instance with a fresh one at the same place, keeping the root's guid, name and local transform. NOT_A_PREFAB_INSTANCE, PREFAB_NOT_LOADED, and PREFAB_MULTIPLE_ROOTS or HIERARCHY_TOO_DEEP when the current asset no longer fits at the instance's place; the instance is left untouched on these errors.

prefab::unpack

[[nodiscard]] CONJURE_API core::result<void> unpack(scene &target, ecs::entity root, bool recursive = false);

Removes the prefab markers of the subtree, stopping at nested instance roots unless recursive. NOT_A_PREFAB_INSTANCE.