The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I have a resource called Inventory and that resource has an array of items, each of team is a resources.

export(Array, Resource) var items = [null, null, null, null]

The resource that i use for items has a lot of info: textures, strings, booleans...

I'm implementing a save/load data script that uses JSON. My problem is that when i save, my json looks like this.


That means when i load i don't get the resource that i want but instead the literal String "Resource:XXXX".

A solution i have for this is save using an unique identifier like and id (int) or a string instead of the whole resource, then use a Match statement and load the corresponding resource.

Is there another straightforward way to do this? I feel like my solution is not flexible at all, if i want to add a lot of items i have to keep updating the paterns of the match .

Godot version 3.5.1
in Engine by (12 points)

1 Answer

+3 votes

Why do you need to convert back and forth from JSON, which doesn't support Godot types? Godot already has a built-in method for natively saving resources - that's how scenes, textures, animations, and every other Resource in Godot is saved - .tres.

Resources can be saved with

and loaded with load():

by (22,191 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.