#Why wait one 'process frame' to use Area3D.GetOverlappingAreas() in Godot with C#?

1 messages · Page 1 of 1 (latest)

echo cape
#

For example, when I wait for one "process frame" Area3D.GetOverlappingAreas() functions correctly. However, calling it without waiting yields incorrect results.

using Godot;
using System;
using BP.GameConsole;

public partial class TestNode : Node3D
{
    [Export] private PackedScene PackedScene;

    public override async void _Ready()
    {
        TestTarget a = PackedScene.CreateOnStage<TestTarget>(this, new Vector3(0.5f,0,0));
        
        await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
        
        if (a.Area3D.GetOverlappingAreas().Count > 0)
        {
            GameConsole.Instance.DebugLog("OK!");
        }
    }
}
plain frost
#

Hi there 😊,

Area3D uses the physics simulation to make judgements about collisions. Adding them and asking for collisions in the same frame before the physics server processes them first will lead to this behavior.

I recommend awaiting the physics process frame, as it's due to be ready before the idle process frame on single threaded game platforms.

echo cape
plain frost
echo cape
versed mural
echo cape
#

It works, thanks!