-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Clarify confusion around property initialization #8293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
raulsntos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing to the documentation!
| // _test is initialized to "one". | ||
| private string _test = "one"; | ||
|
|
||
| // Changing the value from the inspector does trigger the setter in C#. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is important because it lets users know that property setters will be executed by the inspector. It's true that the previous message seems to assume that you've read the GDScript example before, so it could be reworded but I don't think it should be removed entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This data is moved to line 220. I put discussion of @exports at the bottom of the file in both languages so that the order of value assignment matches the order you read the example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I guess it's fine. I still find it a bit weird that information about the exported property is so far from the property itself.
231879c to
6d13fcd
Compare
|
ping @raulsntos :) |
| that code should execute in ``_init()``. Other property or SceneTree-independent | ||
| initializations should also run here. | ||
|
|
||
| Scripts have three types of property assignments that can occur during | ||
| instantiation: | ||
| ``_init()`` triggers before ``_enter_tree()`` or ``_ready()``, but after a script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new text mentions _init so we may want to add a note for C# users. In C#, the _init method doesn't exist and instead users should use the regular class constructor.
The C# constructor will also execute before any of the engine callbacks (_EnterTree, _Ready, etc.) and after what's being referred to here as Initial value assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, adding a note that C#'s _init() equivalent is the constructor.
The previous text implied (at least to me) that there was something special in Godot called an "init assignment value", and that there was special logic determining which kind of assignment was used. In reality, nothing special is happening: the property is initialized, then the constructor may set the value, then exports may as well. I also harmonized the Godot and C# code samples, rather than expecting the user to read both in order. Frankly I almost feel like this would be clearer if the entire section were simply deleted, but I wasn't sure if that would be accepted.
fa140ef to
79863df
Compare
raulsntos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
|
Thanks! |
Clarify the confusing text and code sample around property initialization.
The previous text implied (at least to me) that there was something special in Godot called an "init assignment value", and that there was special logic determining which kind of assignment was used. In reality, nothing special is happening: the property is initialized, then the constructor may set the value, then exports may as well.
I also harmonized the Godot and C# code samples, rather than expecting the user to read both in order.
Frankly I almost feel like this would be clearer if the entire section were simply deleted, but I wasn't sure if that would be accepted.