Call GDScript method from C# passes Custom Resource as EncodedAsObjectID

Godot Version

4.6

Question

Hi!

I’m trying to call a method in a PackedScene with an attached GDscript, passing it an Array of custom Resources, but in the GDscript I receive it as an Array of EncodedAsObjectID instead. (see screenshot)

When trying to use instance_from_id(ugprade) I get the following error:

Error at (11, 37): Invalid argument for “instance_from_id()” function: argument 1 should be “int” but is “res://core/abilities/AbilityUpgrade.cs”.

This is my C# code:

[Export] private PackedScene _upgradeScreenScene;
// ...
private void OnLevelUp(int newLevel)
{
    Node upgradeScreenInstance = _upgradeScreenScene.Instantiate();
        upgradeScreenInstance.Call("set_ability_upgrades", new Array<AbilityUpgrade> { chosenUpgrade });

My custom resource:

[GlobalClass]
public partial class AbilityUpgrade : Resource
{
    [Export] public string Id { get; set; }
    [Export] public string Name { get; set; }
    [Export(PropertyHint.MultilineText)] public string Description { get; set; }
}

It works with simple types like int or string. Tried for about an hour now to get it to work in any way or find something on the internet with no success. How do I get this to work?

Okay, after some sleep and fresh eyes it turns out I was stupid and blind. :sweat_smile:

The problem wasn’t the AbilityUpgraderesource, which was shown a bit odd in the debugger, but working as it should. It was that I called set_ability_upgrade(upgrade)in AbilityUpgradeCardbefore calling add_child(card_instance)which led to the labels here

class_name AbilityUpgradeCard
extends PanelContainer

@onready var name_label: Label = %NameLabel
@onready var description_label: Label = %DescriptionLabel

func set_ability_upgrade(upgrade: AbilityUpgrade) → void:
    name_label.text = upgrade.Name
    description_label.text = upgrade.Description

being null of course. I misread the error for upgrade.Name and upgrade.Descriptionbeing nil. :person_facepalming:

I moved the line with add_childbefore the call to set_ability_upgrade and everything started to work. Ops, my bad!