-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Packed array properties of noncustom resources can't be resized #80950
Comments
I don't think there is a bug in GDScript. Godot properties in C++ are just setter and getter. Arrays (including The built-in classes you listed do not return a direct reference to the data array (they use other structures under the hood). When the getter is called, a new Here is an example in GDScript: var data: PackedByteArray:
set(value):
_data = value.duplicate()
get:
return _data.duplicate()
var _data: PackedByteArray Accordingly, you call I agree that the current API misleading and probably this should not be exposed as |
This is documented for |
235 matches, some false positives
|
Should probably be documented on each of the packed types as well |
Thank you for the clear explanation. |
Seeing that the API for stable has been updated to note that the arrays are copies, I will close this. |
However, this note is missing for arrays and dictionaries. Also, there are some exceptions where built-in pass-by-reference properties takes modification into account, but this is difficult to detect automatically. CC @AThousandShips |
Arrays and dictionaries are a case by case thing as some are passed directly and some are copied, so some manual thing would need to be added |
Godot version
4.1.stable
System information
Godot v4.1.stable - Windows 10.0.19044 - Vulkan (Forward+) - dedicated Quadro P2200 () - Intel(R) Xeon(R) Gold 5222 CPU @ 3.80GHz (8 Threads)
Issue description
For Godot (not custom) Resources, a property that is a PackedArray cannot be resized directly. Copying, resizing, then setting the copy currently works as a work-around.
This behavior is different from custom Resource classes that are built in GDScript instead of C++. These allow resizing of PackedArray properties directly.
Steps to reproduce
Put the attached bug_script.gd code a Control node of a new scene, copy the custom class script gd_custom_class.gd as its own file, then run the scene. The output will mark the point of discrepency.
Output:
Minimal reproduction project
bug_script.gd
gd_custom_class.gd
The text was updated successfully, but these errors were encountered: