GetType() doesn't return the good type

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

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.

:bust_in_silhouette: Reply From: VirgilusGalacticus

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.