Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Twood on January 25, 2022, 01:46:50 AM

Title: Build navmesh in-game action
Post by: Twood 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;
        }
    }
}


Title: Re: Build navmesh in-game action
Post by: RobotGoggles 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?
Title: Re: Build navmesh in-game action
Post by: Twood 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.