From 880ee652893d18dc861b01ae4b751e1bad20cd58 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 00:56:28 +0200 Subject: [PATCH 01/29] providing guidance for being notified about resources changing in tools --- .../plugins/running_code_in_the_editor.rst | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 768c8a7dc09..22e74a8935e 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -245,6 +245,147 @@ angle add a setter ``set(new_speed)`` which is executed with the input from the to run in the editor too. Autoload nodes cannot be accessed in the editor at all. +Getting notified about Resources changing +----------------------------------------- +On some occastions you want your tool to use a resource. However, when you change an +attribute of that resource in the editor, the ``set()`` function of your tool will +not get called. + +.. tabs:: + .. code-tab:: gdscript GDScript + + @tool + class_name MyTool + extends Node + + @export var resource:MyResource: + set(new_resource): + resource = new_resource + _on_resource_set() + + # This will only be called, when you create, delete or paste a resource. + # You will not get an update when tweaking properteis of it. + func _on_resource_set(): + print("My resource was set!") + + .. code-tab:: csharp + + using Godot; + + [Tool] + public partial class MyTool : Node + { + private float _resource = 1; + + [Export] + public MyResource Resource + { + get => _resource; + set + { + _resource = value; + OnResourceSet() + } + } + } + + # This will only be called, when you create, delete or paste a resource. + # You will not get an update when tweaking properteis of it + private void OnResourceSet() + { + print("My resource was set!"); + } + +To get around this problem, you first have to make your resource a tool and make it +emit a signal, whenever a property is set: + +.. tabs:: + .. code-tab:: gdscript GDScript + # Make Your Resource a tool. + @tool + class_name MyResource + extends Resource + + # Declare a signal. + signal property_updated + + @export var property = 1: + + set(new_setting): + property = new_setting + # Emit a signal, when a property is changed. + property_updated.emit() + + .. code-tab:: csharp + + using Godot; + + [Tool] + public partial class MyResource : Resource + { + private float _property = 1; + + # Declare a signal. + [Signal] + public delegate void PropertyUpdatedEventHandler(); + + [Export] + public float Property + { + get => _property; + set + { + _property = value; + #Emit a signal, when property is changed. + EmitSignal(SignalName.PropertyUpdated); + } + } + } + +You then want to connect the signal when a new resource is set: +.. tabs:: + .. code-tab:: gdscript GDScript + + @tool + class_name MyTool + extends Node + + @export var resource:MyResource: + set(new_resource): + resource = new_resource + # Connect the signal you just declared as soon as a new resource is being added. + resource.property_updated.connect(Callable(self, "_on_resource_updated") + + func _on_resource_updated(): + print("My resource just changed!") + + .. code-tab:: csharp + + using Godot; + + [Tool] + public partial class MyTool : Node + { + private float _resource = 1; + + [Export] + public MyResource Resource + { + get => _resource; + set + { + _resource = value; + # Connect the signal you just declared as soon as a new resource is being added. + _resource.PropertyUpdated += OnResourceUpdated; + } + } + } + + private void OnResourceUpdated() + { + print("My Resource just updated!"); + } + Reporting node configuration warnings ------------------------------------- From d9110c90d6846cdd7958d716aea6649721655544 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:16:45 +0200 Subject: [PATCH 02/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 22e74a8935e..6f20f0bb75e 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -258,7 +258,7 @@ not get called. class_name MyTool extends Node - @export var resource:MyResource: + @export var resource: MyResource: set(new_resource): resource = new_resource _on_resource_set() From e9461167daef0701a3c9139169f67ba6262dfe69 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:16:52 +0200 Subject: [PATCH 03/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 6f20f0bb75e..578c3bf600f 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -310,7 +310,6 @@ emit a signal, whenever a property is set: signal property_updated @export var property = 1: - set(new_setting): property = new_setting # Emit a signal, when a property is changed. From db98e9d6362c0b611ec0183915245f4f6e6c99ab Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:17:17 +0200 Subject: [PATCH 04/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 578c3bf600f..7e8e259eb05 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -301,6 +301,7 @@ emit a signal, whenever a property is set: .. tabs:: .. code-tab:: gdscript GDScript + # Make Your Resource a tool. @tool class_name MyResource From 8e685654edfb93c8761c7b30f0bcd60975531c5c Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:17:24 +0200 Subject: [PATCH 05/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 7e8e259eb05..e4ef8147362 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -350,7 +350,7 @@ You then want to connect the signal when a new resource is set: class_name MyTool extends Node - @export var resource:MyResource: + @export var resource: MyResource: set(new_resource): resource = new_resource # Connect the signal you just declared as soon as a new resource is being added. From 51b5e5de1df02f145237517bcef094f39f70d323 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:17:31 +0200 Subject: [PATCH 06/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index e4ef8147362..68c7ff3b5b5 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -325,7 +325,7 @@ emit a signal, whenever a property is set: { private float _property = 1; - # Declare a signal. + // Declare a signal. [Signal] public delegate void PropertyUpdatedEventHandler(); From 819fa1cd33fb38186c7ff7ee8218da8e67970f7c Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:17:38 +0200 Subject: [PATCH 07/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 68c7ff3b5b5..f958b66e3b0 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -383,7 +383,7 @@ You then want to connect the signal when a new resource is set: private void OnResourceUpdated() { - print("My Resource just updated!"); + GD.Print("My Resource just updated!"); } Reporting node configuration warnings From db1ccc4296dc2ca1d6e982c7523ac341384a7a2e Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:17:46 +0200 Subject: [PATCH 08/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index f958b66e3b0..031e5591631 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -313,7 +313,7 @@ emit a signal, whenever a property is set: @export var property = 1: set(new_setting): property = new_setting - # Emit a signal, when a property is changed. + # Emit a signal when the property is changed. property_updated.emit() .. code-tab:: csharp From 2fe6cc9d67ceda300e3961a6e86d2087d3182d36 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:20:12 +0200 Subject: [PATCH 09/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 031e5591631..237532b1c29 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -245,8 +245,9 @@ angle add a setter ``set(new_speed)`` which is executed with the input from the to run in the editor too. Autoload nodes cannot be accessed in the editor at all. -Getting notified about Resources changing ------------------------------------------ +Getting notified when resources change +-------------------------------------- + On some occastions you want your tool to use a resource. However, when you change an attribute of that resource in the editor, the ``set()`` function of your tool will not get called. From 4ed8f80f3b53417cacf8906dc951381dafff2b23 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:20:36 +0200 Subject: [PATCH 10/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 237532b1c29..90b1383355f 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -248,9 +248,9 @@ angle add a setter ``set(new_speed)`` which is executed with the input from the Getting notified when resources change -------------------------------------- -On some occastions you want your tool to use a resource. However, when you change an -attribute of that resource in the editor, the ``set()`` function of your tool will -not get called. +Some times you want your tool to use a resource. However, when you change a +property of that resource in the editor, the ``set()`` method of your tool will +not be called. .. tabs:: .. code-tab:: gdscript GDScript From ff05309c10158f8eda071e273406dc619280253b Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:20:59 +0200 Subject: [PATCH 11/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 90b1383355f..03c57bb8228 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -344,6 +344,7 @@ emit a signal, whenever a property is set: } You then want to connect the signal when a new resource is set: + .. tabs:: .. code-tab:: gdscript GDScript From f6eed4debe5985899035bd16d17d9eca894d3305 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:21:09 +0200 Subject: [PATCH 12/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 03c57bb8228..db42449524b 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -297,7 +297,7 @@ not be called. print("My resource was set!"); } -To get around this problem, you first have to make your resource a tool and make it +To get around this problem you first have to make your resource a tool and make it emit a signal, whenever a property is set: .. tabs:: From 62c2f4e7a73f6e37cb95e71c74cf0571277cc662 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:21:21 +0200 Subject: [PATCH 13/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index db42449524b..9cb8aced664 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -298,7 +298,7 @@ not be called. } To get around this problem you first have to make your resource a tool and make it -emit a signal, whenever a property is set: +emit a signal whenever a property is set: .. tabs:: .. code-tab:: gdscript GDScript From 0cb5f3d8b3ff35ac53158625e4e0c207955b368a Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:26:50 +0200 Subject: [PATCH 14/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 9cb8aced664..325ad84ddac 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -337,7 +337,7 @@ emit a signal whenever a property is set: set { _property = value; - #Emit a signal, when property is changed. + // Emit a signal when the property is changed. EmitSignal(SignalName.PropertyUpdated); } } From b45338a75c407f25ea0b15b4071f181eca9b507d Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:26:59 +0200 Subject: [PATCH 15/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 325ad84ddac..039f858c788 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -377,7 +377,7 @@ You then want to connect the signal when a new resource is set: set { _resource = value; - # Connect the signal you just declared as soon as a new resource is being added. + // Connect the signal you just declared as soon as a new resource is being added. _resource.PropertyUpdated += OnResourceUpdated; } } From 44fed4845a99cfcd0bf8bf4e5e6249f1a5dc3d2e Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:27:10 +0200 Subject: [PATCH 16/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 039f858c788..fbf458a22e4 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -264,8 +264,8 @@ not be called. resource = new_resource _on_resource_set() - # This will only be called, when you create, delete or paste a resource. - # You will not get an update when tweaking properteis of it. + # This will only be called when you create, delete, or paste a resource. + # You will not get an update when tweaking properties of it. func _on_resource_set(): print("My resource was set!") From f8d73201184970a839fc298ed66a33521a0e2c43 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:27:17 +0200 Subject: [PATCH 17/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index fbf458a22e4..7a4f787d934 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -290,8 +290,8 @@ not be called. } } - # This will only be called, when you create, delete or paste a resource. - # You will not get an update when tweaking properteis of it + // This will only be called when you create, delete, or paste a resource. + // You will not get an update when tweaking properties of it. private void OnResourceSet() { print("My resource was set!"); From e9ee39f5e38060dce7d77aca3cb58700519b0c6e Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:27:24 +0200 Subject: [PATCH 18/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 7a4f787d934..0bda8713993 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -294,7 +294,7 @@ not be called. // You will not get an update when tweaking properties of it. private void OnResourceSet() { - print("My resource was set!"); + GD.Print("My resource was set!"); } To get around this problem you first have to make your resource a tool and make it From b3b64d01340302cf413f5d15dcff91d999cdc88c Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:36:06 +0200 Subject: [PATCH 19/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: Raul Santos --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 0bda8713993..312156412ac 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -285,7 +285,7 @@ not be called. set { _resource = value; - OnResourceSet() + OnResourceSet(); } } } From 0c9d756366b0f754a95f8476b082d884b0c78d78 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:36:17 +0200 Subject: [PATCH 20/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: Raul Santos --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 312156412ac..df284c11d1d 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -276,7 +276,7 @@ not be called. [Tool] public partial class MyTool : Node { - private float _resource = 1; + private MyResource _resource; [Export] public MyResource Resource From 9361c4a29bcacfaca05779b62eca381eb4cc08aa Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:36:28 +0200 Subject: [PATCH 21/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: Raul Santos --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index df284c11d1d..ed3bfe62055 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -368,7 +368,7 @@ You then want to connect the signal when a new resource is set: [Tool] public partial class MyTool : Node { - private float _resource = 1; + private MyResource _resource; [Export] public MyResource Resource From ed7d465c761d4f4127cee0777f51f28012217151 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 15:37:08 +0200 Subject: [PATCH 22/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: Raul Santos --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index ed3bfe62055..3483124958b 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -385,7 +385,7 @@ You then want to connect the signal when a new resource is set: private void OnResourceUpdated() { - GD.Print("My Resource just updated!"); + GD.Print("My resource just changed!"); } Reporting node configuration warnings From 5a896b9f5a27e2ce64bd5f0e755366136c9fadcf Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 16:28:49 +0200 Subject: [PATCH 23/29] suggesting to use changed instead of creating a new signal --- .../plugins/running_code_in_the_editor.rst | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 3483124958b..9aad15fb874 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -298,7 +298,7 @@ not be called. } To get around this problem you first have to make your resource a tool and make it -emit a signal whenever a property is set: +emit the ``changed`` signal whenever a property is set: .. tabs:: .. code-tab:: gdscript GDScript @@ -308,14 +308,11 @@ emit a signal whenever a property is set: class_name MyResource extends Resource - # Declare a signal. - signal property_updated - @export var property = 1: set(new_setting): property = new_setting # Emit a signal when the property is changed. - property_updated.emit() + changed.emit() .. code-tab:: csharp @@ -326,10 +323,6 @@ emit a signal whenever a property is set: { private float _property = 1; - // Declare a signal. - [Signal] - public delegate void PropertyUpdatedEventHandler(); - [Export] public float Property { @@ -338,7 +331,7 @@ emit a signal whenever a property is set: { _property = value; // Emit a signal when the property is changed. - EmitSignal(SignalName.PropertyUpdated); + EmitSignal(SignalName.Changed); } } } @@ -355,10 +348,10 @@ You then want to connect the signal when a new resource is set: @export var resource: MyResource: set(new_resource): resource = new_resource - # Connect the signal you just declared as soon as a new resource is being added. - resource.property_updated.connect(Callable(self, "_on_resource_updated") + # Connect the changed signal as soon as a new resource is being added. + resource.changed.connect(Callable(self, "_on_resource_changed") - func _on_resource_updated(): + func _on_resource_changed(): print("My resource just changed!") .. code-tab:: csharp @@ -377,13 +370,13 @@ You then want to connect the signal when a new resource is set: set { _resource = value; - // Connect the signal you just declared as soon as a new resource is being added. - _resource.PropertyUpdated += OnResourceUpdated; + // Connect the changed signal as soon as a new resource is being added. + _resource.Changed += OnResourceChanged; } } } - private void OnResourceUpdated() + private void OnResourceChanged() { GD.Print("My resource just changed!"); } From f51aef48a8207c923ce8ecf5cbeff660df62c1a4 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 16:31:20 +0200 Subject: [PATCH 24/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 9aad15fb874..f4286571d88 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -349,7 +349,7 @@ You then want to connect the signal when a new resource is set: set(new_resource): resource = new_resource # Connect the changed signal as soon as a new resource is being added. - resource.changed.connect(Callable(self, "_on_resource_changed") + resource.changed.connect(_on_resource_changed) func _on_resource_changed(): print("My resource just changed!") From 0658f711a7719288b56ee62de1961c24ac4007d5 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 16:38:00 +0200 Subject: [PATCH 25/29] guidance on disconnecting old resources when new one is set --- .../plugins/running_code_in_the_editor.rst | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index f4286571d88..a5a6aa5d6cc 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -381,6 +381,31 @@ You then want to connect the signal when a new resource is set: GD.Print("My resource just changed!"); } +Lastly, you should to disconnect the signal as the old resource being used and changed somewhere else +would cause unneeded updates. +.. tabs:: + .. code-tab:: gdscript GDScript + + @export var resource: MyResource: + set(new_resource): + # Disconnect the signal if the previous resource was not null. + if resource != null: resource.changed.disconnect(_on_resource_changed) + resource = new_resource + resource.changed.connect(_on_resource_changed) +.. code-tab:: csharp + [Export] + public MyResource Resource + { + get => _resource; + set + { + // Disconnect the signal if the previous resource was not null. + if (_resource != null) { _resource.Changed -= OnResourceChanged; } + _resource = value; + _resource.Changed += OnResourceChanged; + } + } + Reporting node configuration warnings ------------------------------------- From f78ba0f8ff9fe3d1d12e8e0504b06321afe946fd Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 16:39:14 +0200 Subject: [PATCH 26/29] Update tutorials/plugins/running_code_in_the_editor.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index a5a6aa5d6cc..742e8ac3908 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -392,7 +392,9 @@ would cause unneeded updates. if resource != null: resource.changed.disconnect(_on_resource_changed) resource = new_resource resource.changed.connect(_on_resource_changed) + .. code-tab:: csharp + [Export] public MyResource Resource { From 5d4b4d49df55305641fdade0bedd475beb24fcf4 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 16:41:24 +0200 Subject: [PATCH 27/29] further formatting enhancements Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 742e8ac3908..43e5b01b952 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -383,13 +383,15 @@ You then want to connect the signal when a new resource is set: Lastly, you should to disconnect the signal as the old resource being used and changed somewhere else would cause unneeded updates. + .. tabs:: .. code-tab:: gdscript GDScript @export var resource: MyResource: set(new_resource): # Disconnect the signal if the previous resource was not null. - if resource != null: resource.changed.disconnect(_on_resource_changed) + if resource != null: + resource.changed.disconnect(_on_resource_changed) resource = new_resource resource.changed.connect(_on_resource_changed) @@ -402,7 +404,10 @@ would cause unneeded updates. set { // Disconnect the signal if the previous resource was not null. - if (_resource != null) { _resource.Changed -= OnResourceChanged; } + if (_resource != null) + { + _resource.Changed -= OnResourceChanged; + } _resource = value; _resource.Changed += OnResourceChanged; } From 1d84250eaaf791b57f683b06538079432127e39a Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 16:48:46 +0200 Subject: [PATCH 28/29] fixing typo Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 43e5b01b952..8050890a638 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -395,7 +395,7 @@ would cause unneeded updates. resource = new_resource resource.changed.connect(_on_resource_changed) -.. code-tab:: csharp + .. code-tab:: csharp [Export] public MyResource Resource From 5880494f2c68272394f41f97b4f85c285929db29 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 27 Apr 2024 17:15:34 +0200 Subject: [PATCH 29/29] using pre-existing shorthand for emitting signal Co-authored-by: Raul Santos --- tutorials/plugins/running_code_in_the_editor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/plugins/running_code_in_the_editor.rst b/tutorials/plugins/running_code_in_the_editor.rst index 8050890a638..b91912a3c1a 100644 --- a/tutorials/plugins/running_code_in_the_editor.rst +++ b/tutorials/plugins/running_code_in_the_editor.rst @@ -331,7 +331,7 @@ emit the ``changed`` signal whenever a property is set: { _property = value; // Emit a signal when the property is changed. - EmitSignal(SignalName.Changed); + EmitChanged(); } } }