Documentation
¶
Overview ¶
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 graphics.gd/classdb/Node.Instance.Owner property).
Note: The node doesn't need to own itself.
Example: Load a saved scene:
package main import ( "graphics.gd/classdb/Node" "graphics.gd/classdb/PackedScene" "graphics.gd/classdb/Resource" ) func ExamplePackedSceneLoad(parent Node.Instance) { var scene = Resource.Load[PackedScene.Instance]("res://scene.tscn").Instantiate() parent.AddChild(scene) }
Example: Save a node with different owners. The following example creates 3 objects: graphics.gd/classdb/Node2D (node), graphics.gd/classdb/RigidBody2D (body) and graphics.gd/classdb/CollisionObject2D (collision). collision is a child of body which is a child of node. Only body is owned by node and Instance.Pack will therefore only save those two nodes, but not collision.
package main import ( "graphics.gd/classdb/CollisionShape2D" "graphics.gd/classdb/Engine" "graphics.gd/classdb/Node2D" "graphics.gd/classdb/PackedScene" "graphics.gd/classdb/ResourceSaver" "graphics.gd/classdb/RigidBody2D" ) func ExamplePackedSceneSave() { var node = Node2D.New() var body = RigidBody2D.New() var collision = CollisionShape2D.New() body.AsNode().AddChild(collision.AsNode()) node.AsNode().AddChild(body.AsNode()) body.AsNode().SetOwner(node.AsNode()) // Change owner of `body`, but not of `collision`. var scene = PackedScene.New() var result = scene.Pack(node.AsNode()) // Only `node` and `body` are now packed. if result == nil { var err = ResourceSaver.Save(scene.AsResource(), "res://path/name.tscn", 0) // Or "user://..." if err != nil { Engine.Raise(err) } } }
Index ¶
- func Instantiate[T Node.Any](packed_scene Instance) T
- type Advanced
- type Any
- type Expanded
- type Extension
- type GenEditState
- type ID
- type Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsPackedScene() Instance
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) CanInstantiate() bool
- func (self Instance) ID() ID
- func (self Instance) Instantiate() Node.Instance
- func (self Instance) Pack(path Node.Instance) error
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type Is
- func (self Is[T]) AsObject() [1]gd.Object
- func (self Is[T]) AsPackedScene() Instance
- func (self Is[T]) AsRefCounted() [1]gd.RefCounted
- func (self Is[T]) AsResource() Resource.Instance
- func (self Is[T]) CanInstantiate() bool
- func (self Is[T]) GetState() [1]gdclass.SceneState
- func (self Is[T]) Instantiate() T
- func (self Is[T]) Pack(path T) error
- func (self *Is[T]) SetObject(obj [1]gd.Object) bool
- func (self *Is[T]) UnsafePointer() unsafe.Pointer
- func (self Is[T]) Virtual(name string) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Expanded ¶
type Expanded [1]gdclass.PackedScene
func (Expanded) Instantiate ¶
func (self Expanded) Instantiate(edit_state GenEditState) Node.Instance
Instantiates the scene's node hierarchy. Triggers child scene instantiation(s). Triggers a [Node.NotificationSceneInstantiated] notification on the root node.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsPackedScene ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResource ¶
type GenEditState ¶
type GenEditState int //gd:PackedScene.GenEditState
const ( // If passed to [Instance.Instantiate], blocks edits to the scene state. GenEditStateDisabled GenEditState = 0 // If passed to [Instance.Instantiate], provides local scene resources to the local scene. // // Note: Only available in editor builds. GenEditStateInstance GenEditState = 1 // If passed to [Instance.Instantiate], provides local scene resources to the local scene. Only the main scene should receive the main edit state. // // Note: Only available in editor builds. GenEditStateMain GenEditState = 2 // It's similar to [GenEditStateMain], but for the case where the scene is being instantiated to be the base of another one. // // Note: Only available in editor builds. GenEditStateMainInherited GenEditState = 3 )
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.PackedScene
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsPackedScene ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
func (Instance) CanInstantiate ¶
Returns true if the scene file has nodes.
func (Instance) Instantiate ¶
Instantiates the scene's node hierarchy. Triggers child scene instantiation(s). Triggers a [Node.NotificationSceneInstantiated] notification on the root node.
func (Instance) Pack ¶
Packs the 'path' node, and all owned sub-nodes, into this graphics.gd/classdb/PackedScene. Any existing data will be cleared. See graphics.gd/classdb/Node.Instance.Owner.
type Is ¶
type Is[T Node.Any] [1]gdclass.PackedScene
Is wraps a PackedScene with a type.
func (Is[T]) AsPackedScene ¶
func (Is[T]) AsRefCounted ¶
func (self Is[T]) AsRefCounted() [1]gd.RefCounted
func (Is[T]) AsResource ¶
func (Is[T]) CanInstantiate ¶
Returns [code]true[/code] if the scene file has nodes.
func (Is[T]) GetState ¶
func (self Is[T]) GetState() [1]gdclass.SceneState
Returns the [SceneState] representing the scene file contents.
func (Is[T]) Instantiate ¶
func (self Is[T]) Instantiate() T
Instantiates the scene's node hierarchy. Triggers child scene instantiation(s). Triggers a [constant Node.NOTIFICATION_SCENE_INSTANTIATED] notification on the root node.
func (Is[T]) Pack ¶
Packs the [param path] node, and all owned sub-nodes, into this [PackedScene]. Any existing data will be cleared. See [member Node.owner].