How do I get Godot to recognize custom classes with C#?

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

I’m trying to send a custom class InvItem through a signal _UpdateHotbarItem. When the signal is declared as this in the Inventory.cs class:

public delegate void _UpdateHotbarItem(string id, int index, bool side, string data);

it’s fine. However, when I add InvItem item to the parameters and build the project, the signal disappears from the signal list in the editor and I get a couple errors. On startup, I get _get_signal: Unknown type of signal parameter 'item' in 'Inventory'. On signal connection, I get connect: In object of type 'Area2D': Attempt to connect nonexistent signal '_UpdateHotbarItem' to method 'KinematicBody2D.UpdateHotbarItem, and on emitting the signal, I get two more errors, Attempted to convert an unmarshallable managed type to Variant. Name: 'InvItem' Encoding: 18, and Can't emit non-existing signal "_UpdateHotbarItem".

When I remove the InvItem item, and change the signal emitters and receiving methods, all four of those errors disappear.
In both cases, the InvItem export I have, shown here:

InvItem heldItem = null;

throws an error, this error being _get_member_export: Unknown exported member type: 'Inventory.heldItem'.

It seems to me that Godot doesn’t realize the InvItem class in the CustomDataTypes namespace in CustomDataTypes.cs exists. How do I get Godot to recognize it, so I can use it in signals, export statements, and similar things?

:bust_in_silhouette: Reply From: tx350z

I know this is an old post but it has not been answered. I hit the same problem.

After some experimenting I discovered all objects passed as parameters in an EmitSignal calls must inherit from Godot.Object or a descendant type.