Apex PATH + world streamer + off grid navigation

  • August 15, 2017 at 06:38 #21741


    First of all thank you for the great work you did with apex path.

    I’m using world streamer to stream my entire world.

    My Player is NOT driven by apex path but my NPC does.

    Basicly here is my setup :

    1/ Multiple grid streamed by World Streamer based on THE PLAYER position. (that let me control the number of apex grids loaded in my game instead of loading Grids based on the NPCs positions)
    2/ NPC are spawned in the begining of the game in specific postions (houses, specific points on the maps…)

    What i’m trying to do is to let my NPCs navigate in the world even if they are not in a loaded grid or even if the destination point is not in the loaded grid too. Of corse when they navigate in a non loaded grid there is no obstacle avoidance and i’m fine with that. What i’m excpecting is when they reach a loaded grid (when they are nearby the player) they will start to avoid obstacles.

    To achieve that i used the scripts in “offGrid navigation” exemple and thats work fine !

    The issues i’m facing is :

    1/ When an NPC is spawned nearby the player (in a loaded terrain) and start the move to another destination, when the player move (and the terrain is unloaded by world streamer) the npc stop and throw an error complaing about the terrain that not exist anymore (seems to be related to TerrainHeightMap..) ! how i can make apex ignore the terrain HeightMap when the terrain is unloaded and let the npc continue his way ?

    2/ After the unloading of the terrain the NPC fall down (i’m using rigidbodies set to kinematic) but i geuss the second issue is related to the first one ?

    Thank you for your help

    August 15, 2017 at 11:34 #21747

    Hi Amynox,

    Thanks for your post.

    If you do not need height navigation at all, remove the “Default Height Navigator” component from your NPCs, disable ‘height map generation’ on your grid(s) and rebake grid(s) if necessary. Thus, there should be no height navigation provided by Apex.

    If you do need height navigation, you could try live raycasting instead of height map generation. You can change this on the GameWorld’s components (including on the GridComponent).

    August 15, 2017 at 14:39 #21754

    Hi Rami,

    Thank you for the quick answer.

    Actually i need the height navigation ! i switched to Live raycasting in the game world as you suggested. In the grid component it says (Height navigation mode has been set to raycast (on game world). hence no height map will be created) so i geuss i dont have anything to change in the grid config.

    When i enter play mode and when the terrain get unloaded i’m getting the same error as before :

    MissingReferenceException: The object of type ‘Terrain’ has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Terrain.SampleHeight (Vector3 worldPosition) (at C:/buildslave/unity/build/artifacts/generated/common/modules/Terrain/TerrainsBindings.gen.cs:323)
    Apex.WorldGeometry.TerrainHeightMap.SampleHeight (Vector3 position) (at Assets/Apex/Apex Path/Scripts/WorldGeometry/TerrainHeightMap.cs:96)
    Apex.Steering.HeightNavigation.HeightMapSphericalThreePointProvider.GetHeightDelta (Apex.Steering.SteeringInput input) (at Assets/Apex/Apex Path/Scripts/Steering/HeightNavigation/HeightMapSphericalThreePointProvider.cs:98)
    Apex.Steering.HeightNavigation.DefaultHeightNavigator.GetHeightOutput (Apex.Steering.SteeringInput input, Single effectiveMaxSpeed) (at Assets/Apex/Apex Path/Scripts/Steering/HeightNavigation/DefaultHeightNavigator.cs:97)
    Apex.Steering.SteerableUnitComponent.Steer (Single deltaTime) (at Assets/Apex/Apex Path/Scripts/Steering/SteerableUnitComponent.cs:456)
    Apex.Steering.SteerableUnitComponent.FixedUpdate () (at Assets/Apex/Apex Path/Scripts/Steering/SteerableUnitComponent.cs:209)

    Thank your for your help

    • This reply was modified 1 year, 2 months ago by amynox.
    • This reply was modified 1 year, 2 months ago by amynox.
    August 15, 2017 at 15:40 #21758

    Ok so a few things you should look at.

    1. GridStatusMessage is sent when a grid disables or initializes and listening to that will allow you to act, i.e. implement IHandleMessage in some handler that can then make he necessary changes to unit settings etc. based on grid availability.

    2. A TerrainHeightMap is added automatically at run time if Unity Terrain is detected. This seems to clash with your use case. Either stop it from doing this by editing the GameServicesInitializerComponent.cs or remove it after it is added.

    3. Instead add a FixedHeightMapComponent to the world so that the units have something to query when off the grid OR disable height nav for the units when off grid.

    August 18, 2017 at 02:54 #21773

    Hi Geminor,

    For now i switched Height Sampler on my NPC to Ray Cast + following rami suggestions and it works.

    however, by sticking with Height Map (+deleting TerrainHeightMap + FixedHeightMapComponent when offgrid) i think i will get better performance than raycasting ?

    I watched all the videos on youtube but i’m still having some questions :

    1/ How i can detecte in which Grid my Unit is in as it moves ? (i need to force my NPC to replane when he enter a new grid **) as at the moment of the “initial path request” the unit doesn’t know about the STATIC obstacles that exist in the destination grid(not loaded).
    ** the use of “GridStatusMessage” is not relevant ion my case as the grids only loads based on Player position and not NPCs (the destination might be in the other side of the world)

    2/ I need my NPC to follow the terrain road (not to walk into the terrain grass) to get to the destination point. Of course the destination point is placed by the player and can or can’t be on the road.

    I tried using the Patrol Points component to quickly draw points on all the terrain possible roads and ask for path using the “VIA” params (that i found by accident in the forum) but the NPC walk to the first point (in the direction of the destination) and simply stops with “Destination reached” message!

    here is the code i used :

    What i’m excepcting is that the Path request (+ VIA param) will only pick “relevant” points on the “Patrol Points” and draw its way to the destination (even if the destination is in the grass). Of course i’ve checked that all the points in the “Patrol Points” are not in a blocked grid…

    Thank you for the help

    • This reply was modified 1 year, 2 months ago by amynox.
    August 18, 2017 at 15:08 #21777

    however, by sticking with Height Map (+deleting TerrainHeightMap + FixedHeightMapComponent when offgrid) i think i will get better performance than raycasting ?
    It’s a question of memory load vs cpu load. Height map memory costs entriely depends on the terrain. If it is totally flat there is no cost, if it is very irregular the cost is very high.
    Raycasting has no memory cost, but adds a small cpu overhead. This overhead scales linearly with the number of agents.

    1/ How i can detecte in which Grid my Unit is in as it moves ?
    You can alwyas get the grid covering a given position via the GridManager’s GetGrid(pos) method.

    2/ I need my NPC to follow the terrain road
    Via points work like waypoints in the path. Goind from A to D via BC, means start at A go to B go to C go to D. The paths for each segment will be calculated as the shortest path possible.

    Such path request can partially complete, e.g. the path can be A to C and stop at C because no path existed at that time from C to D.

    Another approach to make units favor roads is to apply costs to cells. Apply a high cost to non road cells and a low one to road cells. This will not prevent paths off road, but will favor roads unless a less costly path exists off road.

    August 18, 2017 at 17:13 #21779

    Thanks for the quick answer, I start to understand better now.

    Concerning the cell cost. Didn’t see anything about it on the videos. Can you point me to some Tuto, docs or even forum post that give some exemple on how to use it for my case needs ?

    Thank you

    August 19, 2017 at 12:48 #21782

    Cell costs are not documented as we never implemented full support for it.
    The foundation is there however. In the simplest form, you just assign a cost to a cell directly via its cost property.

    You can also have a look at the ICellCostStrategy which allows you to implement more advanced cost processing.

    Be aware however that since a grid is shared among all agents, if a cost only applies to some, costs need to be applied and removed dynamically before and after path requests.

You must be logged in to reply to this topic.