#GetRid() returns null?

2 messages · Page 1 of 1 (latest)

rigid harbor
#

Question
I try to spawn an object near another object, so I use NavigationServer3D.MapGetClosestPoint to get it, but when it runs it gives out an error that the parameter map is null, but it can’t be null.


    Node3D target;
    NavigationRegion3D navMesh;

    public override void _Ready()
    {
        target = GetTree().Root.GetNode("Game").GetNode("Map").GetNode("floor1").GetNode("objects").GetNode("grabber").GetNode<Node3D>("Target");
        navMesh = GetTree().Root.GetNode("Game").GetNode("Map").GetNode("floor1").GetNode<NavigationRegion3D>("NavRegion");
    }

    public override void _Process(double delta)
    {
        Vector3 movePos = NavigationServer3D.MapGetClosestPoint(navMesh.GetRid(), target.Position);
        this.GetParent<CharacterBody3D>().Position = movePos;
    }```
Note that it doesn’t run every frame, I deleted some of the code that wasn’t needed to answer my questions.

Could anybody help me out? (Godot Version 4.2.1)
rigid harbor
#

Whoops, forgot to add the error messages:

  <C++-Fehler>   System.InvalidCastException
  <C++-Quelle>   :0 @ object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object)
  <Stacktrace>   :0 @ object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object)
                 NodeExtensions.cs:182 @ T Godot.Node.GetParent<T>()
                 eddie.cs:46 @ void eddie._Process(double)
                 Node.cs:2111 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
                 eddie_ScriptMethods.generated.cs:68 @ bool eddie.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
                 CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)