Changing the speed of a NavAgent in runtime

Hello,
I have a NavAgent with a logic nodes trait (Car).
I want to set a different speed at runtime with logic nodes.
I tried this, but it fails. I may misunderstand something…
image

Hi, I can give you a small workaround, but I am not sure if it would work.

After you add the NavAfesnt trait to the object, click on Edit trait and then change the following lines:

@prop
var speed: Float = 5;

to

@prop
public var speed: Float = 5;

and then try with the same logic node trees.

Thanks for your answer, but if I edit the script it does not work and crash the game with this error :

Trace: TypeError: Cannot read property ‘setPath’ of null
at :1744:10
at Object. (:2966:4)
at eval (eval at _emscripten_run_script (eval at kha_Assets.loadBlobFromPath.fileName (unknown source)), :1:29)
at _emscripten_run_script (eval at kha_Assets.loadBlobFromPath.fileName (unknown source), :9239:7)
at Array.__Z8findPathffffffii (eval at kha_Assets.loadBlobFromPath.fileName (unknown source), :85815:2)
at Array._ZN10emscripten8internal7InvokerIvJffffffiiEE6invokeEPFvffffffiiEffffffii (eval at kha_Assets.loadBlobFromPath.fileName (unknown source), :169366:35)
at dynCall_viddddddii (eval at kha_Assets.loadBlobFromPath.fileName (unknown source), :176293:38)
at dynCall_viffffffii_1 (eval at makeDynCaller (eval at kha_Assets.loadBlobFromPath.fileName (unknown source)), :4:12)
at Object.findPath (eval at new
(eval at kha_Assets.loadBlobFromPath.fileName (unknown source)), :15:1Trace: %s

If I close Blender and relaunch, it does not crash, but as soon as I open the script one time (even if I don’t edit it), it crashes again…

Trace: TypeError: Cannot read property ‘setPath’ of null

This error isn’t due to changing the speed variable to public. Somehow the NavAgent is null when the setPath function is called somewhere… If you could reproduce this in a separated .blend and send it for testing, would be good to see what exactly is happening. Anyway it should work, i don’t see anything wrong in your node setup

1 Like

@mokauno

I was able to reproduce the error you mentioned. So I made some improvements to the nodes as described here.

Once this is included in the Armory, you can set individual speeds for the NavAgents.

3 Likes

That’s great ! Thanks :slight_smile:
Sorry for the late answer. I have put the navmesh example on c: root to be sure to not have path problems.
The example runs well, but if I just touch NavAgent.hx with an editor, the example crashes (not at start, only when the cube is supposed to move).
I don’t understand why… is it about user’s rights or something else ?
To be sure I also updated Armory with git.

Well, thanks again. You all make a so good job. I did’nt use Armory for months, and I am really surprised by the ease of the node system at this time.

I’m working on a new game and it’s a real pleasure :+1:t2:

2 Likes

I did some tests and it is not due to the path of the project. The issue is that when you click on edit NavMesh, it automatically moves the NavAgent trait from armory.trait.NavAgent to arm.NavAgent. This causes issues.

If you havent figured out already, to fix the crashing:

  1. Remove the NavAgent.hx file from projectFolder\Sources\arm
  2. Remove the Haxe trait NavAgent.hx from the NavAgent object.
  3. Re-add the NavAgent trait as a bundled trait to the object.

This basically reverts clicking the “Edit Script” button.

Cool! Good luck with your new game :slightly_smiling_face:

1 Like