Resource.resource_local_to_scene = true creates SetGet problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By VastView

When I make a Resource var I’m using local to the scene of a saved scene that I instance a lot, it makes the getter in a setget var in my Resource’s code break.

Code that breaks when I switch my custom Resrouce to local to scene:

extends Resource

class_name Stats

export(Dictionary) var stats = {
	"dps": 0.0,
	"cdr": 0.0,
	"armour": 0.0,
	"movespeed": 0.0,
	"tenacity": 0.0,
	"h_regen": 0.0,
	"e_regen": 0.0

func get_stats():
	var res = {}
	for key in stats:
		res[Enums.stat[key]] = stats[key]
	return res

func set_stat(stat_type, new_value):
	stats[Enums.stat.keys()[stat_type]] = new_value

Short explanation of the stats var:
This dictionary gets set up with string values for keys, but when I get my stats dictionary from another script, I convert it’s keys to their corresponding enum values. (When Resource is local to scene, the getter breaks, because when it refers to stats it gets a dictionary with enum values as keys, not strings.

:bust_in_silhouette: Reply From: VastView

I found out what the problem is!

When you have a Resource that contains a variable: var a: Dictionary setget , _get_a; and you use .duplicate(true) on it, it creates a new Resource and starts filling it up with copies of the other Resources values. So, when it tries to copy the variable a from the original Resource, it says new_resource.a = original_resource.a, which calls the getter function that setget for var a: Dictionary setget , _get_a specifies.

This is why my code breaks. Because my code converts my stats dictionary 's keys from strings to their corresponding enum’s int values in the getter function for the variable. This make the new duplicate of the original Resource have int keys instead of string keys, and thus breaks the getter function’s functionality.