Detect collisions for specific group with PhysicsServer2D

Godot Version

4.2.1 (Mono)

Question

I’m trying to detect collisions using PhysicsServer2D in C#.
So far I tried using IntersectShape() but I can’t really understand how to use it.

This is how far I got, however…

	Resource hb = ResourceLoader.Load<Resource>("res://Data/Assets/BulletsHB/bulletHB01.tres");
	PhysicsShapeQueryParameters2D query = new PhysicsShapeQueryParameters2D();
	PhysicsDirectSpaceState2D directSpaceState;
	public override void _Ready()
	{
		directSpaceState = GetWorld2D().DirectSpaceState;
	}
	public SimpleBullet()
	{
		query.Shape = hb;
		query.CollideWithBodies = true;
		query.CollisionMask = 261;
		TopLevel = true;
	}

    public override void _PhysicsProcess(double delta)
    {
        base._PhysicsProcess(delta);
		query.Transform = GlobalTransform;
		Dictionary result = directSpaceState.IntersectShape(query, 1);
		if(result.Contains("collider")) { QueueFree(); }
		
		Position += Transform.Y * 750f * (float)delta;
    }

(the scene is called “SimpleBullet” btw, thus public SimpleBullet())

… this is the error that I get when running the project.
Cannot implicitly convert type 'Godot.Collections.Array<Godot.Collections.Dictionary>' to 'Godot.Collections.Dictionary'

I can’t use normal Area2D via editor because I need the game to be able to handle a lot of bullets.

I want to be able to detect a node that touches the bullet shown in here and to check what group it’s in or just check it’s metadata where I could save it’s type and depending on it do various functions.
How can I do it? Any help appreciated.

What I understand from the your error and the documentation is that the IntersectShape method actually returns an array of dictionaries, not a single dictionary.

Your C# variable type should be Dictionary[] I think

Just tried that but it doesn’t change anything.

Error stays the same?

Yes, unfortunately.