playMaker

Author Topic: Build navmesh in-game action  (Read 2612 times)

Twood

  • Junior Playmaker
  • **
  • Posts: 76
Build navmesh in-game action
« on: January 25, 2022, 01:46:50 AM »
--------  OUTDATED VERSION SCROLL DOWN TO UPDATE 1  5/14/2022 ----------


Hi, I'm starting to make actions for some of the things that I use call method or get property for.

One of them is for Unity's advanced Navmesh extensions: https://docs.unity3d.com/Manual/NavMesh-BuildingComponents.html

This action just runs the build command on NavMeshSurface so you can change your navmesh's build when you want in-game. You would have to change the actual layout with other techniques like changing object's layers, or using modifier volumes.

Also let me know if there's any issue, first time I tried making a PM custom action!

--------  OUTDATED VERSION SCROLL DOWN TO UPDATE 1  5/14/2022 ----------

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.NavMesh)]
    [Tooltip("Activates rebuilding the nav mesh on a surface in real-time. Requires the extra Unity extensions for Nav Mesh. \n" +
            "https://github.com/Unity-Technologies/NavMeshComponents")]

    public class BuildNavMesh : FsmStateAction
    {
        [CheckForComponent(typeof(UnityEngine.AI.NavMeshSurface))]
        [RequiredField]

        public FsmGameObject navMeshSurface;
        private GameObject go;
        private UnityEngine.AI.NavMeshSurface _surface;


        private void GetSurface()
        {

            if (navMeshSurface == null)
            {
                return;
            }
            go = navMeshSurface.Value;
            _surface = go.GetComponent<UnityEngine.AI.NavMeshSurface>();
        }

        public override void OnEnter()

        {
            GetSurface();
            _surface.BuildNavMesh();
            Finish();
        }

        public override void Reset()
        {
            navMeshSurface = null;
        }
    }
}


« Last Edit: May 14, 2022, 05:24:16 PM by Twood »

RobotGoggles

  • Playmaker Newbie
  • *
  • Posts: 35
Re: Build navmesh in-game action
« Reply #1 on: April 17, 2022, 01:35:48 AM »
Hey I was looking for this exact action, but when I import this script I get the error: NavMeshSurface does not exist in the namespace "UnityEngine.AI"

I definitely have the navigation package installed, as I'm currently using NavMesh Surfaces and Links in my project, so I don't think that's it.  :(

Any idea?
When life hands you insomnia, make video games.

Twood

  • Junior Playmaker
  • **
  • Posts: 76
Re: Build navmesh in-game action
« Reply #2 on: May 14, 2022, 05:02:12 PM »
------   UPDATE 1  5/14/2022  -------------

----- THIS IS THE RECOMMENDED VERSION TO DOWNLOAD ----

So something might changed in the extension components or whatever, but I had to update this to work in a new project. I have changed the script and this is the one you should use at this point.


This was tested in unity 2021.1.7f1, with Ai Navigation 1.0.0-exp.4  installed from package manager by: adding a registry package by name and add the com.unity.ai.navigation package.

Let me know if there's any issue, this should solve the importing issue.
« Last Edit: May 14, 2022, 05:31:14 PM by Twood »

Twood

  • Junior Playmaker
  • **
  • Posts: 76
Re: Build navmesh in-game action
« Reply #3 on: December 19, 2022, 08:39:57 PM »
I haven't changed it except for UPDATE 1, because it works for me. Do you have an issue? What unity version and where are you downloading the navmesh extensions?