Skip to content
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

Saved resource loses data when duplicated #94242

Open
Tracked by #80877
vvvvvvitor opened this issue Jul 11, 2024 · 4 comments
Open
Tracked by #80877

Saved resource loses data when duplicated #94242

vvvvvvitor opened this issue Jul 11, 2024 · 4 comments

Comments

@vvvvvvitor
Copy link

Tested versions

  • Reproducible in: 4.2.2stable

System information

Godot v4.2.2.stable (15073af) - Freedesktop SDK 23.08 (Flatpak runtime) - Wayland - Vulkan (Forward+) - integrated Intel(R) UHD Graphics (ICL GT1) () - Intel(R) Core(TM) i3-1005G1 CPU @ 1.20GHz (4 Threads)

Issue description

When duplicating a saved resource, it's data seems to get lost.

The resource:

image

The code:

const ITEM_INDEX: Array[Item] = [
	preload("res://res/items/item_abyss_garden_key.tres")
]

# [...]

@export var icon: Texture = PLACEHOLDER_ICON
@export var name: String = "item"
@export var display_name: String = "Item"
@export_multiline var description: String = "The ultimate weapon!"

# [...]

static func get_item_from_index(item_id: int) -> Item:
	return ITEM_INDEX[item_id].duplicate()

When trying to get the values from the resource it returns the values that were predefined, in this case, if I try to get the "name" property, it'll return "item" instead of "garden_key".

When also trying to access the data of the resource directly (load("path").property) I get an error that says the property does not exist, even though it should

Invalid get index 'name' (on base: 'Resource').

Steps to reproduce

  • Make a resource;
  • Save it;
  • Load and duplicate it;
  • Try to access it's data.

Minimal reproduction project (MRP)

N/A

@Calinou
Copy link
Member

Calinou commented Jul 12, 2024

@dalexeev
Copy link
Member

dalexeev commented Jul 12, 2024

This is due to cyclic dependencies and loading order. You want to have a constant in a class with instances of the same class, but this does not work as expected. If you move the constant to another class (ItemDB), it will work. Also you can use a static variable instead of constant and load() instead of preload(), then it will work in the same class (Item).

MRP: test-94242.zip

@vvvvvvitor
Copy link
Author

This is due to cyclic dependencies and loading order. You want to have a constant in a class with instances of the same class, but this does not work as expected. If you move the constant to another class (ItemDB), it will work. Also you can use a static variable instead of constant and load() instead of preload(), then it will work in the same class (Item).

MRP: test-94242.zip

Ah, I see, should I close this issue then?

@dalexeev
Copy link
Member

I think no. Even if we don't support this case, it should probably produce an error since constants are evaluated at compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Up for grabs
Development

No branches or pull requests

3 participants