Skip to content

Engine → Scene → prefab.h

prefab_builder

Syntax

class CONJURE_API prefab_builder

Constructors

AccessSignatureDescription
publicexplicit prefab_builder( const ecs::component_registry &registry);

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~prefab_builder();Destroys the component images.

Variables

AccessNameTypeDefaultDescription
privatemIdsscene_component_ids{}
privatemNodesstd::vector<node>{}
privatemRegistryconst ecs::component_registry *nullptr
publicNO_PARENTstatic constexpr u320xFFFFFFFFu

Functions

Public

add_component_json

[[nodiscard]] core::result<void> add_component_json(
    u32 nodeIndex,
    core::string_id component,
    const core::json::value &value);

Adds a component by registered name from JSON. UNKNOWN_COMPONENT for an unknown name, SERIALIZATION_FAILED for malformed JSON, BUILDER_INVALID for an unknown node or a component the builder writes itself (parent, children, guid, prefab_link, name, local_transform, depth tags, companions, inactive): name and transform come from add_node.

add_component_raw

[[nodiscard]] core::result<void> add_component_raw(
    u32 nodeIndex,
    ecs::component_id component,
    std::span<const std::byte> bytes);

Adds a component from an object image of exactly the registered size.

add_node

[[nodiscard]] u32 add_node(
    u32 parentIndex,
    std::string_view name,
    const local_transform &transform = {});

Adds a node and returns its index. parentIndex is NO_PARENT for the root; an unknown parent makes build() fail with BUILDER_INVALID.

add_tag

[[nodiscard]] core::result<void> add_tag(
    u32 nodeIndex,
    ecs::component_id component);

Adds a tag component. BUILDER_INVALID when the id is not a tag.

build

[[nodiscard]] core::result<prefab_document> build(
    std::string_view name) const;

Produces the document: guids generated, parent and siblingIndex from insertion order, prefab_link on every entry, entries in hierarchy order. BUILDER_INVALID unless exactly one root exists and every parent index names an earlier-or-later node without a cycle.

node_count

[[nodiscard]] u32 node_count() const noexcept;

Number of nodes added.

Private

destroy_images

void destroy_images() noexcept;

is_reserved

[[nodiscard]] bool is_reserved(
    ecs::component_id id) const noexcept;