NavMesh - Discord Import

How can I use the navmesh baked on Unity with Three Pathfinding? I’ve seen some posts about this on the Discord, but I don’t fully understand what I need to do. Do I have to add a serialized field in my C# code and then use it in my script? I really don’t understand what I’m supposed to do.

Original Post on Discord

by user 691445074055397447

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

Hello Boss15493,

To use a Unity-baked navmesh with Three Pathfinding in Needle Engine, you would follow these general steps:

  1. Export the NavMesh from Unity: Unity’s NavMesh can be exported to a format that Three Pathfinding can understand using a tool or script that converts the NavMesh data to a mesh or a compatible format (like .obj or .gltf).

  2. Load the Exported NavMesh in Needle Engine: Once you have the exported NavMesh format, you can load it into your Needle Engine project as you would with any other mesh resource.

  3. Implement Pathfinding: Leverage the Three Pathfinding library by integrating it with your project. You will instantiate the Three Pathfinding’s Pathfinder class, giving it the navmesh geometry to build its internal zones.

  4. Serialized Field: If you want to reference the navmesh in the Needle Engine project, you can define a serialized field in your TypeScript component that references the mesh. This lets you access the navmesh directly at runtime.

Here is a conceptual example in TypeScript showing how you might define a serialized field and use the Three Pathfinding:

*thread_3gaGsG4CxikbGF879d2EYScp*

how can i do this how can I do this Export the NavMesh from Unity: Unity’s NavMesh can be exported to a format that Three Pathfinding can understand using a tool or script that converts the NavMesh data to a mesh or a compatible format (like .obj or .gltf).?

by user 691445074055397447

Here is what I found for you :brain: Discord

To export the NavMesh from Unity to a format compatible with Three Pathfinding, you can follow these steps:

  1. Create a Script in Unity: Write a custom script in Unity to extract the NavMesh data and convert it into a compatible format like .obj or .gltf. This script should extract the necessary geometry and other information needed for pathfinding.

  2. Extract the NavMesh:

    • The script can extract the relevant geometry and data from the Unity NavMesh.
    • It may need to convert the NavMesh data into a format that can be used in another environment.
  3. Export to .obj or .gltf:

    • Convert the extracted data to a mesh format such as .obj or .gltf, preserving the necessary information for pathfinding.
    • Alternatively, you can export the geometry data and build the necessary structures for pathfinding within the new environment directly within your script.

For more detailed guidance on writing the specific script or extracting NavMesh data in Unity, you may want to refer to Unity’s documentation, relevant forums, or communities where Unity gamedevs or pathfinding experts share their knowledge. They can provide specific information on accessing the NavMesh data and exporting it to a compatible format.

Additionally, the Discord channel may be a good place to ask for examples or guidance on how others have achieved this, as community members may have scripts or tools specifically built for this purpose.

0 messages left GPT 3.5
thread_3gaGsG4CxikbGF879d2EYScp
Thanks for your feedback!

If you convert the nevmesh to a regular unity mesh and reference it from one of your scripts you get a three.js mesh in needle engine (in the script reference) that u can use

No need to convert it to a extra model file

ohh ok ok and how can i do that ?

by user 691445074055397447

@kipash :cactus: can you share a script?

Hey :wave: i’ve extracted the code from the game jam into a unreleased sample which you can find here: https://github.com/needle-tools/needle-engine-samples/tree/navmesh/package/Runtime/Navmesh

Here’s a quick demo: https://engine.needle.tools/samples-uploads/navmesh/

For simplicity i would recommend cloning the samples repo on the navmesh branch. And add that local package to your unity project.

This way, the sample will show up in the Samples browser:
image.png

Let me know if you have further questions

Hey, thank you so much, really! This helps me a lot !!!

by user 691445074055397447

I have a question, so I opened the sample you provided and I’ve been looking at it. I want to know how you make the button that says ‘Generate Navmesh’ appear in the inspector. I copied the same code into my project because I really want to understand how it works, but in the inspector, I only see a serialized field. I understand that you do this in the code gen on the C# script, but I checked the code generation of the repository you send me, and I don’t see anything. If that’s the case, what should I do to achieve something like that?


by user 691445074055397447

So, this is Unity specific. For any C# component you add to game objects you can write so called Custom Editors. With that you can change how the component in the inspector is being drawn.
You can find the custom editor class here: https://github.com/needle-tools/needle-engine-samples/blob/navmesh/package/Runtime/Navmesh/Scripts/Editor/NavmeshEditor.cs

Have you moved all the files?

You can also add the local samples package to any project and use it directly without manually moving it :+1:

Ohhhhh, ok, ok. I was confused; I thought that was done in the C# of the code generation. Thanks !

by user 691445074055397447

okay. Yes, but I just want to understand how you do this :laughing: Thank you very much

by user 691445074055397447

I’ve been trying to apply it to my project, but I don’t understand what I’m doing wrong. I think the navmesh is not being generated correctly. I get this error in the console, and when I click Generate Navmesh in unity i get this


by user 691445074055397447