Resource property is empty at runtime

Godot Version

v4.3.stable.fedora [77dcf97d8]

Question

I am using resources in my game to help keep things sane, and it has been working wonderfully. However I’ve just started seeing the strangest behaviour. One property - called ingredients currently (though I have tried many different names, in case I was accidentally bumping into a reserved word) - in one of my resources is full in the inspector, but empty at runtime.

All the other fields in the resource are populated, and if I change a value in the inspector it will also be changed at runtime, but this one field is permanently empty.

I have tried:

  • creating a new version of this resource
  • renaming the problematic property
  • creating a new property with the same type (both become empty)

I created a _to_string function on the object, to help me debug this, which I’ll paste here:

func _to_string() -> String:
	return "action(name: %s, cooldown: %s, ingredients: %s, output items: %s, output Actors: %s)" % [name, cooldown, ingredients, outputItems, outputActors]

To debug this, I have loaded and printed the resource, I’ve captured a screenshot that you can see here:

In this image you can see:

  • if I build the same data structure directly and print it, it is correct at runtime
  • You can see the resource in the inspector on the right has values in the ingredients field.
  • You can see the resource is loaded and then directly printed
  • You can see in the output area that the Ingredients field is empty.

just to add some notes on the structure of the resources:
action:

  • ingredients: array of stacks

stack:

  • contains item and a quantity

item:

  • unique type of item, e.g. “copper” also has a maxStackSize defined, which is read by the stack resource.

ok, I’ve believe I have found the cause of the issue. My stack object had a custom constructor which seems to make it impossible to use that object in the inspector.

I removed the constructor and instead created a sort of metafactory function for it, and it is all working as expected now.

1 Like