Godot Version
4.2.2
Question
Hello,
I’m having an error message when trying to load an extension of an Interaction resource into a .tres (the Interaction resource is a custom resource). The error roughly translates :
The selected resource (Resource) does not match to any awaited type for this property (Interaction)
Here are the simplifed scripts
interaction.gd
class_name Interaction
extends Resource
@export var text: String
func execute() -> void:
pass
spider_interaction.gd
extends Interaction
func execute() -> void:
print("Spider interaction : " + text)
monster_resource.gd
class_name MonsterResource
extends Resource
@export var healt: int
@export var interaction: Interaction
I have a spider_interaction.tres file which is a linked to the spider_interaction.gd script
And I have a spider.tres file linked to the monster_resource.gd script.
I have the error message when I try to load the spider_interaction.tres file in the interaction variable.
If you need more context as to what I am trying to do, I have a combat menu with basics interactions (Attack, Defend, Run) and I want to add other interactions based on the monster the player is fighting
I guess I can bypass the issue by declaring a Resource and not an Interaction, but it’s going to be teddious…
Tell me if you need more information !
Antoine
You could try doing a casting
Interaction_var = load(tres) as Interaction
Hello
I’m trying to load a resource manually via the godot resource interface (with an @export variable). So I don’t think I can use a code for that ?
do you mean save a Resource as a tres?
and could you show the code related to the error?
anyway I dont have this issue and this is what i do
var player_config : PlayerConfig # extends resource
const player_config_data_path : String = "user://player_config.tres"
# saving
ResourceSaver.save(player_config, player_config_data_path)
# loading
player_config = ResourceLoader.load(player_config_data_path,"PlayerConfig", ResourceLoader.CACHE_MODE_REPLACE)
i guess I don’t need to cast the resource, since it will just be implicitly cast by my variable declaration.
Hmm I’ll try to explain better :
I have created a “spider_interaction.tres” file. The script linked to this Resource is “spider_interaction.gd” (which is an extention of a custom Interaction class).
I am creating a “spider.tres” file, which is a MonsterResource. I am using Godot interface to set the variables. One of the variable is named interaction and is of type Interaction.
While editing the “spider.tres” file in the Godot interface, I can load a file to attach it to the interaction variable. I get the error when I try to load the “spider_interaction.tres” file.
I am assuming that since “spider_interaction.tres” is an extention of Interaction it should work, but maybe I’m wrong. I am definitly no expert in OOP ^^’
I hope this explains better ?
A tres file of monster resource is a text file of the properties of the Resource class. And it should not be modified directly.
Once a tres file is loaded it becomes a Resource class. In this state should be modified. But modifying the instance will not update the tres.
You need to use ResourceSaver to dynamically update it. Or after editing the resource. Click the drop down in the inspector and manually save the resource again.
I think there’s a misunderstanding ^^'.
I’m trying to set the variable with this interface in the Godot program:

Or isn’t it the correct way ?