Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Area3D node error calling from signal "input_event" - Method not found #67009

Closed
BrandonGillis opened this issue Oct 6, 2022 · 7 comments · Fixed by #67023
Closed

C#: Area3D node error calling from signal "input_event" - Method not found #67009

BrandonGillis opened this issue Oct 6, 2022 · 7 comments · Fixed by #67023

Comments

@BrandonGillis
Copy link

BrandonGillis commented Oct 6, 2022

Godot version

v4.0.beta2.mono.official [f8745f2]

System information

Windows 11 x64

Issue description

I made a simple 3D Scene with an Area3D node to detect mouse movement with a CollisionShape3D.
When registering the input_event signal inside a C# script and I hover my mouse over the CollisionShape it try to fire the input_event signal but doesn't find the method associated to it and spam this error :

E 0:00:00:0910   emit_signalp: Error calling from signal 'input_event' to callable: 'Area3D(Area3d.cs)::_on_area_3d_input_event': Method not found..
  <Source C++>   core/object/object.cpp:1057 @ emit_signalp()

Steps to reproduce

  1. Download the minimal reproduction project below
  2. There's one C# script on the Area3D node with the input_event signal binded to it with the following code :
using Godot;
using System;

public partial class Area3d : Area3D
{
	private void _on_area_3d_input_event(object camera, object @event, Vector3 position, Vector3 normal, int shape_idx)
	{
		GD.Print("collision event");
	}
}
  1. Run the game and move your mouse inside the game.
  2. You should be spammed inside the debugger with this error :
    image

Minimal reproduction project

Area3DInputEventBug.zip

@akien-mga akien-mga added this to the 4.0 milestone Oct 7, 2022
@akien-mga
Copy link
Member

CC @godotengine/dotnet

Didn't check but a potential cause of this error is if the callback parameters don't properly match what is expected by the signal. I don't know if object is valid here or if it should be further specified.

If this is the problem, we really need to improve the error message to point out when the method name is correct but the signature isn't.

@BrandonGillis
Copy link
Author

To add some details the signature of the current method is the one generated automatically from the Godot editor

@raulsntos
Copy link
Member

raulsntos commented Oct 7, 2022

Signals currently only support 64-bit types so the int parameter should be long. The object parameter also looks weird because we no longer support System.Object it likely should be Godot.Variant.

@BrandonGillis
Copy link
Author

BrandonGillis commented Oct 7, 2022

I confirm that updating the method signature to the following fix the method not found error :

	private void _on_area_3d_input_event(Variant camera, Variant @event, Vector3 position, Vector3 normal, long shape_idx)
	{
		GD.Print("collision event");
	}

Strong typing also works good :

private void _on_area_3d_input_event(Camera3D camera, InputEvent @event, Vector3 position, Vector3 normal, int shape_idx)

Keeping an int for the shape_idx make it work too :

private void _on_area_3d_input_event(Variant camera, Variant @event, Vector3 position, Vector3 normal, int shape_idx)

Things to improve :

  • Error message as @akien-mga suggested, this is not really a method not found but a signature issue.
  • int type in the signature should trigger an error ?
  • The generated signature from Godot Editor when connecting a signal

Animation

@raulsntos
Copy link
Member

We used System.Object (now Godot.Variant) when we don't know or can't figure out what the type is, in this case it seems we should be able to provide more concrete types though from the core API.

For the int parameter, it likely works in this case because internally the signal is emitted using an int but in other cases it may not so we have to assume it's a long unless otherwise specified and the core API right now doesn't specify this for signals or virtual methods (see godotengine/godot-proposals#5403 (comment)).

@BrandonGillis
Copy link
Author

Should we split the method not found into another issue or is it ok to keep it in this one?

I would like to try fixing that one if it's ok, as I think it would be a nice candidate for a first contribution

@raulsntos
Copy link
Member

raulsntos commented Oct 7, 2022

There is an open issue we can use to keep track of that: #35910

I don't think it would be an easy fix for a first contribution, it likely requires changing Godot.Object.InvokeGodotClassMethod to be able to return godot_variant_call_error and then modify the ScriptMethodsGenerator appropriately but I don't know if that change would be desired since making it return a boolean was likely intentional.

@raulsntos raulsntos moved this to To Assess in 4.x Priority Issues Nov 21, 2022
@raulsntos raulsntos moved this from To Assess to In Progress in 4.x Priority Issues Nov 21, 2022
Repository owner moved this from In Progress to Done in 4.x Priority Issues Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants