Colorguardian10
Colorguardian10

Reputation: 23

How to use BodyShapeEntered in Godot C#?

I am trying to use the BodyShapeEntered signal for an Area3D in C#. I can't figure out what the delegate should look like for this event. I get the following compile error: "No overload for 'OnCollision' matches delegate 'Area3D.BodyShapeEnteredEventHandler'" Unfortunately, I can't find any info about what parameters I should use for this handler, if this isn't it. My code matches the description in https://docs.godotengine.org/en/4.2/classes/class_area3d.html#signals

I am using version 4.2. Here is my code:

using Godot;
using System;

public partial class LocationExit : Area3D
{
    public static readonly PackedScene DefaultExitScene = ResourceLoader.Load<PackedScene>("res://Overworld/Overworld.tscn");
    
    public PackedScene ExitScene;//alternate scene to exit to
    string StoryVariableOnExit;//increments this variable in the story on collision
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        this.BodyShapeEntered += OnCollision;
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
    }
    
    
    private void OnCollision(Rid body_rid, Node3D body, int body_shape_index, int local_shape_index)
    {
        //cannot use, this will not compile
    }
}

Upvotes: 2

Views: 230

Answers (1)

Theraot
Theraot

Reputation: 40295

I believe you need to use long instead of int:

    private void OnCollision(Rid body_rid, Node3D body, long body_shape_index, long local_shape_index)
    {
        // ...
    }

Upvotes: 1

Related Questions