h8man/NavMeshPlus

Does this work with Prefabs?

dhzd84 opened this issue · 2 comments

Sorry for the very novice question as I'm new to Unity...
I am generating Asteroids which are a Prefab, and I'm using the runtime code to try to find the collider mesh with all Asteroids on scene. This doesn't seem to work. Of course, if I add the Prefab into the scene and run the game the mesh works fine.

I currently call this when the navmesh starts:
Surface2D.BuildNavMeshAsync();

Should I be calling it after every Asteroid prefab is created/destroyed? Or am I doing something else wrong? The Player and Asteroid are setup correctly, and the navmesh obj which contains Navigation CollectSources2d has this script attached:

using UnityEngine;
using NavMeshPlus.Components;

public class NavMesh : MonoBehaviour
{
    public NavMeshSurface Surface2D;
    // Start is called before the first frame update
    void Start()
    {
        Physics2D.SyncTransforms();
        Surface2D.BuildNavMeshAsync();
    }
.......

Thank you!

from wiki:

Important note: Collider's bounds not getting updated to match the transform until 'LateUpdate()' is called. Force the update by calling Physics2D.SyncTransforms() before calling 'BuildNavMesh()' if you baking navmesh at runtime.

Important note: Physics updated only in fixed update, that is running in different time period than regular update. So its is not possible to generate physics in Awake/Start and call 'BuildNavMesh()' before 'LateUpdate()' to bake new geometry at runtime.

does this answers your question?

from wiki:

Important note: Collider's bounds not getting updated to match the transform until 'LateUpdate()' is called. Force the update by calling Physics2D.SyncTransforms() before calling 'BuildNavMesh()' if you baking navmesh at runtime.
Important note: Physics updated only in fixed update, that is running in different time period than regular update. So its is not possible to generate physics in Awake/Start and call 'BuildNavMesh()' before 'LateUpdate()' to bake new geometry at runtime.

does this answers your question?

Yes it does, I misunderstood that part in wiki...thank you!