0 votes

Hi,

I have strange behaviour when I want to get the type of my resource.

Here is the code where I use a list of my resource :

public void Build(List<CraftRecipe> recipeList){        
    foreach(CraftRecipe recipe in recipeList){
        GD.Print("The recipe type is : "+recipe.GetType());
        GD.Print("The craft Recipe type is : "+ typeof(CraftRecipe));
    }
}

And it return to me this :

The recipe type is : ItemResource
The craft Recipe type is : CraftRecipe

PS: the "ItemResource" is another resource that I use in my project (it's one of the CraftRecipe's properties).

I've tried with others resources :

foreach(CraftRecipe recipe in recipeList){
        GD.Print("The recipe type is : "+recipe.GetType());
        GD.Print("The craft Recipe type is : "+ typeof(CraftRecipe));

        GD.Print("The recipe itemResource type is : "+recipe.ItemResource.GetType());
        GD.Print("The ItemResource type is : "+ typeof(ItemResource));

    }

And there is the result :

The recipe type is : ItemResource
The craft Recipe type is : CraftRecipe
The recipe itemResource type is : Godot.StreamTexture
The ItemResource type is : ItemResource

Thanks for your answers.

Godot version 3.2.3
in Engine by (21 points)

1 Answer

0 votes
Best answer

Hi,

I found that the problem appeared because my resources was strangely linked to the other, so when i changed the script of one it was changing the script of the other.

I advise you to use Godot.Collection.Array instead of List because it didn't throw an error when using List. It throw a cast error when using GD arrays.

by (21 points)
selected by
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 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 webmaster@godotengine.org with your username.