Godot Version
4.1.3
Question
while trying to connect a newly spawned (instantiated) monster to a player:
if (!Mob._dungeon_monsters[i].HasSignal(“MonsterVanished”))
Mob._dungeon_monsters[i].Connect(“MonsterVanished”, new Callable(_player, “_OnMonsterVanished”));
I get the following error during runtime:
E 0:01:35:0028 Godot.NativeInterop.NativeFuncs.generated.cs:345 @ void Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr , IntPtr , System.Void** , System.Void* ): Signal ‘MonsterWon’ is already connected to given callable ‘CharacterBody2D(Player.cs)::_OnMonsterWon’ in that object.
<C++ Error> Method/function failed. Returning: ERR_INVALID_PARAMETER
<C++ Source> core/object/object.cpp:1294 @ connect()
Godot.NativeInterop.NativeFuncs.generated.cs:345 @ void Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr , IntPtr , System.Void** , System.Void* )
NativeCalls.cs:6402 @ Int32 Godot.NativeCalls.godot_icall_3_709(IntPtr , IntPtr , Godot.NativeInterop.godot_string_name , Godot.Callable& , UInt32 )
GodotObject.cs:792 @ Godot.Error Godot.GodotObject.Connect(Godot.StringName , Godot.Callable , UInt32 )
MOB_spawning.cs:206 @ void MOB_spawning.DistributeMOBS()
MOB_spawning.cs:121 @ void MOB_spawning._Process(Double )
Node.cs:2087 @ Boolean Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
CanvasItem.cs:1374 @ Boolean Godot.CanvasItem.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
Node2D.cs:516 @ Boolean Godot.Node2D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
CollisionObject2D.cs:661 @ Boolean Godot.CollisionObject2D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
PhysicsBody2D.cs:89 @ Boolean Godot.PhysicsBody2D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
StaticBody2D.cs:131 @ Boolean Godot.StaticBody2D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
MOB_spawning_ScriptMethods.generated.cs:73 @ Boolean MOB_spawning.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(IntPtr , Godot.NativeInterop.godot_string_name* , Godot.NativeInterop.godot_variant** , Int32 , Godot.NativeInterop.godot_variant_call_error* , Godot.NativeInterop.godot_variant* )
if I check if the signal exists I don’t get the error, but it also doesn’t seem to work while running (ie. “_OnMonsterVanished” doesn’t get hit):
if (!Mob._dungeon_monsters[i].HasSignal(“MonsterVanished”))