PackedScene.xml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="PackedScene" inherits="Resource" version="3.4">
  3. <brief_description>
  4. An abstraction of a serialized scene.
  5. </brief_description>
  6. <description>
  7. A simplified interface to a scene file. Provides access to operations and checks that can be performed on the scene resource itself.
  8. 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 [code]owner[/code] property on [Node]).
  9. [b]Note:[/b] The node doesn't need to own itself.
  10. [b]Example of loading a saved scene:[/b]
  11. [codeblock]
  12. # Use `load()` instead of `preload()` if the path isn't known at compile-time.
  13. var scene = preload("res://scene.tscn").instance()
  14. # Add the node as a child of the node the script is attached to.
  15. add_child(scene)
  16. [/codeblock]
  17. [b]Example of saving a node with different owners:[/b] The following example creates 3 objects: [code]Node2D[/code] ([code]node[/code]), [code]RigidBody2D[/code] ([code]rigid[/code]) and [code]CollisionObject2D[/code] ([code]collision[/code]). [code]collision[/code] is a child of [code]rigid[/code] which is a child of [code]node[/code]. Only [code]rigid[/code] is owned by [code]node[/code] and [code]pack[/code] will therefore only save those two nodes, but not [code]collision[/code].
  18. [codeblock]
  19. # Create the objects.
  20. var node = Node2D.new()
  21. var rigid = RigidBody2D.new()
  22. var collision = CollisionShape2D.new()
  23. # Create the object hierarchy.
  24. rigid.add_child(collision)
  25. node.add_child(rigid)
  26. # Change owner of `rigid`, but not of `collision`.
  27. rigid.owner = node
  28. var scene = PackedScene.new()
  29. # Only `node` and `rigid` are now packed.
  30. var result = scene.pack(node)
  31. if result == OK:
  32. var error = ResourceSaver.save("res://path/name.scn", scene) # Or "user://..."
  33. if error != OK:
  34. push_error("An error occurred while saving the scene to disk.")
  35. [/codeblock]
  36. </description>
  37. <tutorials>
  38. <link title="2D Role Playing Game Demo">https://godotengine.org/asset-library/asset/520</link>
  39. </tutorials>
  40. <methods>
  41. <method name="can_instance" qualifiers="const">
  42. <return type="bool">
  43. </return>
  44. <description>
  45. Returns [code]true[/code] if the scene file has nodes.
  46. </description>
  47. </method>
  48. <method name="get_state">
  49. <return type="SceneState">
  50. </return>
  51. <description>
  52. Returns the [code]SceneState[/code] representing the scene file contents.
  53. </description>
  54. </method>
  55. <method name="instance" qualifiers="const">
  56. <return type="Node">
  57. </return>
  58. <argument index="0" name="edit_state" type="int" enum="PackedScene.GenEditState" default="0">
  59. </argument>
  60. <description>
  61. Instantiates the scene's node hierarchy. Triggers child scene instantiation(s). Triggers a [constant Node.NOTIFICATION_INSTANCED] notification on the root node.
  62. </description>
  63. </method>
  64. <method name="pack">
  65. <return type="int" enum="Error">
  66. </return>
  67. <argument index="0" name="path" type="Node">
  68. </argument>
  69. <description>
  70. Pack will ignore any sub-nodes not owned by given node. See [member Node.owner].
  71. </description>
  72. </method>
  73. </methods>
  74. <members>
  75. <member name="_bundled" type="Dictionary" setter="_set_bundled_scene" getter="_get_bundled_scene" default="{&quot;conn_count&quot;: 0,&quot;conns&quot;: PoolIntArray( ),&quot;editable_instances&quot;: [ ],&quot;names&quot;: PoolStringArray( ),&quot;node_count&quot;: 0,&quot;node_paths&quot;: [ ],&quot;nodes&quot;: PoolIntArray( ),&quot;variants&quot;: [ ],&quot;version&quot;: 2}">
  76. A dictionary representation of the scene contents.
  77. Available keys include "rnames" and "variants" for resources, "node_count", "nodes", "node_paths" for nodes, "editable_instances" for base scene children overrides, "conn_count" and "conns" for signal connections, and "version" for the format style of the PackedScene.
  78. </member>
  79. </members>
  80. <constants>
  81. <constant name="GEN_EDIT_STATE_DISABLED" value="0" enum="GenEditState">
  82. If passed to [method instance], blocks edits to the scene state.
  83. </constant>
  84. <constant name="GEN_EDIT_STATE_INSTANCE" value="1" enum="GenEditState">
  85. If passed to [method instance], provides local scene resources to the local scene.
  86. [b]Note:[/b] Only available in editor builds.
  87. </constant>
  88. <constant name="GEN_EDIT_STATE_MAIN" value="2" enum="GenEditState">
  89. If passed to [method instance], provides local scene resources to the local scene. Only the main scene should receive the main edit state.
  90. [b]Note:[/b] Only available in editor builds.
  91. </constant>
  92. </constants>
  93. </class>