-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
duplicate() don't copy variables values in Resources #37222
Comments
Please mention the Godot version you're using in issue description. Also, please upload a minimal reproduction project to make this easier to troubleshoot 🙂 |
Unity Minimal Project: https://ufile.io/w0crj713 The workaround is setting the variables of the duplicated resource manually, in our case we spent hours troubleshooting this, and we came to the conclusion that we didn't even set all of the variables, our IDE should have been also more helpfull. (we have dozens and dozens of vars that affect our code). With big projects, this is a must have... |
Isn't duplicate(subresources=false) what you are looking for? |
@Anutrix No. It was the first things I've tried. |
Is this only failing for user created properties/fields or does the same apply to the native class properties? |
If by native class property you mean a something that is present in the original Resource inherited class, I don't think it fails, i.e. #37222 (comment) in the first screenshot If you want I can open a proposal for adding this clone/duplicate functionality. Since I noticed some time after opening this issue that Actually I had replaced |
i got same error on gdScript
output:
|
id love to have a duplicate() functions which also duplicates the internal variables, because I use a class as a Data Structure and once I duplicate it (with whatever paremeters, if true or 4), the variables stay on but all are empty. Its basicallly a preload().new() but duplicate should exactly duplicate that class. Now I added own duplicate function for the data structure class like above, but this is just a temporary solution. |
Confirmed, the bug is still in Godot 3.3. I have a particle resource with a color (purple by default). I set the color before adding it. The simulation function duplicates it before adding it. It should be the set color, but it remains purple. var color = Color.purple Adding code: var water = Fluid2DParticle.new()
water.color = Color.blue
fluids.fill_area(Rect2(start, size), water) The fill_area function: func fill_area(area: Rect2, p: Fluid2DParticle):
for x in range(area.position.x, area.end.x):
for y in range(area.position.y, area.end.y):
_add_point(Vector2(x, y), p.duplicate())
update() |
You can use your own clone function as workaround, i use this solution.
|
Duplicate of #3393. |
Last reproduced in Godot version: da4eb71
We use Godot C#, and we don't see a proper way to get a real duplication of the Resource like in Unity (
InventoryItem clone = UnityEngine.Object.Instantiate(this) as InventoryItem
). In the docs says that Resource are similar to Unity Scriptable Objects but they're not for most proper use cases. In our inventory system, our items can't have the stackable option (for example having a max of 10 items per slot - for the same item), becausethis.Duplicate() as InventoryItem
doesn't work properly. (assuming that this one is the equivalent of the refered Unity method)Edit: Maybe we assumed wrongly the actual bold text, since
duplicate
is used many times in the core of the engine, but the actual exposed thing can be misleading, and people can assume that does what the unity like func does.I previously thought that this was related to #3393, but then we realised that it was better to create another issue.
The text was updated successfully, but these errors were encountered: