PrefabTemplate
¶
A prefab template contains information that is required to create a tree of Node instances.
The typical workflow for creating nodes in code is to:
Inherits properties and message types from PrefabTemplateMetadata.
Creates a tree of nodes by instantiating a prefab template node. Automatically determines the type of the KanziObject of the root node of the instantiated node tree and returns the ObjectRef which contains the reference to it.
Creates a tree of nodes according to the instructions that are stored in the prefab template data. The returned nodes are initially detached and for them to become active you need to add them to the existing node tree.
-- Acquire a PrefabTemplate resource.
local prefab = contextNode:tryAcquireResource("kzb://project/Prefabs/Caption")
-- Instantiate the resource.
local instance = prefab:instantiate("CaptionNode")
-- Prefab root type is automatically determined.
instance:setText("Caption")
-- Add instantiated node to the node tree.
local parentNode = contextNode:lookupNode("..")
parentNode:addChild(instance)
rootName | (string) | The name of the instantiated root node. Overrides the name that is defined in the prefab template data. The child names are not overridden. |
(ObjectRef) | An instance of an ObjectRef, containing the reference to the root of the instantiated node tree. |