PackedScene.xml 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="PackedScene" inherits="Resource" category="Core" version="3.1">
  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 node it owns get saved (see [code]owner[/code] property on [Node]). Note that the node doesn't need to own itself.
  9. Example of saving a node with different owners: 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].
  10. [codeblock]
  11. # create the objects
  12. var node = Node2D.new()
  13. var rigid = RigidBody2D.new()
  14. var collision = CollisionShape2D.new()
  15. # create the object hierarchy
  16. rigid.add_child(collision)
  17. node.add_child(rigid)
  18. # change owner of rigid, but not of collision
  19. rigid.owner = node
  20. var scene = PackedScene.new()
  21. # only node and rigid are now packed
  22. var result = scene.pack(node)
  23. if result == OK:
  24. ResourceSaver.save("res://path/name.scn", scene) # or user://...
  25. [/codeblock]
  26. </description>
  27. <tutorials>
  28. </tutorials>
  29. <demos>
  30. </demos>
  31. <methods>
  32. <method name="can_instance" qualifiers="const">
  33. <return type="bool">
  34. </return>
  35. <description>
  36. Returns [code]true[/code] if the scene file has nodes.
  37. </description>
  38. </method>
  39. <method name="get_state">
  40. <return type="SceneState">
  41. </return>
  42. <description>
  43. Returns the [code]SceneState[/code] representing the scene file contents.
  44. </description>
  45. </method>
  46. <method name="instance" qualifiers="const">
  47. <return type="Node">
  48. </return>
  49. <argument index="0" name="edit_state" type="int" enum="PackedScene.GenEditState" default="0">
  50. </argument>
  51. <description>
  52. Instantiates the scene's node hierarchy. Triggers child scene instantiation(s). Triggers [Node]'s [code]NOTIFICATION_INSTANCED[/code] notification on the root node.
  53. </description>
  54. </method>
  55. <method name="pack">
  56. <return type="int" enum="Error">
  57. </return>
  58. <argument index="0" name="path" type="Node">
  59. </argument>
  60. <description>
  61. Pack will ignore any sub-nodes not owned by given node. See [member Node.owner].
  62. </description>
  63. </method>
  64. </methods>
  65. <members>
  66. <member name="_bundled" type="Dictionary" setter="_set_bundled_scene" getter="_get_bundled_scene">
  67. A dictionary representation of the scene contents.
  68. 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.
  69. </member>
  70. </members>
  71. <constants>
  72. <constant name="GEN_EDIT_STATE_DISABLED" value="0" enum="GenEditState">
  73. If passed to [method instance], blocks edits to the scene state.
  74. </constant>
  75. <constant name="GEN_EDIT_STATE_INSTANCE" value="1" enum="GenEditState">
  76. If passed to [method instance], provides local scene resources to the local scene. Requires tools compiled.
  77. </constant>
  78. <constant name="GEN_EDIT_STATE_MAIN" value="2" enum="GenEditState">
  79. If passed to [method instance], provides local scene resources to the local scene. Only the main scene should receive the main edit state. Requires tools compiled.
  80. </constant>
  81. </constants>
  82. </class>