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)