Check for errors when saving in the ResourceSaver example documentation

This also replaces a non-breaking space that was accidentally added in
the EditorFeatureProfile documentation.

This closes #31393.

(cherry picked from commit 2f46f1e7b1)
This commit is contained in:
Hugo Locurcio 2020-04-17 22:27:01 +02:00 committed by Rémi Verschelde
parent 3a2cdf7d5b
commit e8ead37725
2 changed files with 8 additions and 6 deletions

View File

@ -72,7 +72,7 @@
<argument index="0" name="path" type="String"> <argument index="0" name="path" type="String">
</argument> </argument>
<description> <description>
Saves the editor feature profile to a file in JSON format. It can then be imported using the feature profile manager's [b]Import[/b] button or the [method load_from_file] button. Saves the editor feature profile to a file in JSON format. It can then be imported using the feature profile manager's [b]Import[/b] button or the [method load_from_file] button.
</description> </description>
</method> </method>
<method name="set_disable_class"> <method name="set_disable_class">

View File

@ -9,23 +9,25 @@
[b]Note:[/b] The node doesn't need to own itself. [b]Note:[/b] The node doesn't need to own itself.
[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]. [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].
[codeblock] [codeblock]
# Create the objects # Create the objects.
var node = Node2D.new() var node = Node2D.new()
var rigid = RigidBody2D.new() var rigid = RigidBody2D.new()
var collision = CollisionShape2D.new() var collision = CollisionShape2D.new()
# Create the object hierarchy # Create the object hierarchy.
rigid.add_child(collision) rigid.add_child(collision)
node.add_child(rigid) node.add_child(rigid)
# Change owner of rigid, but not of collision # Change owner of `rigid`, but not of `collision`.
rigid.owner = node rigid.owner = node
var scene = PackedScene.new() var scene = PackedScene.new()
# Only node and rigid are now packed # Only `node` and `rigid` are now packed.
var result = scene.pack(node) var result = scene.pack(node)
if result == OK: if result == OK:
ResourceSaver.save("res://path/name.scn", scene) # Or "user://..." var error = ResourceSaver.save("res://path/name.scn", scene) # Or "user://..."
if error != OK:
push_error("An error occurred while saving the scene to disk.")
[/codeblock] [/codeblock]
</description> </description>
<tutorials> <tutorials>