PackedScene
An abstraction of a serialized scene.
PackedScene.swift:26class PackedScene
A simplified interface to a scene file. Provides access to operations and checks that can be performed on the scene resource itself.
Can be used to save a node to a file. When saving, the node as well as all the nodes it owns get saved (see owner
property).
Example of loading a saved scene:
Example of saving a node with different owners: The following example creates 3 objects: Node2D
(node
), RigidBody2D
(body
) and CollisionObject2D
(collision
). collision
is a child of body
which is a child of node
. Only body
is owned by node
and pack(path:)
will therefore only save those two nodes, but not collision
.
Superclasses
class Resource
Base class for serializable objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
func canInstantiate(
) -> Bool Returns
true
if the scene file has nodes.func getState(
) -> SceneState? Returns the
SceneState
representing the scene file contents.func instantiate(editState: PackedScene.GenEditState
) -> Node? Instantiates the scene’s node hierarchy. Triggers child scene instantiation(s). Triggers a
Node
notificationSceneInstantiated```` notification on the root node.func pack(path: Node?
) -> GodotError Packs the
path
node, and all owned sub-nodes, into thisPackedScene
. Any existing data will be cleared. Seeowner
.