Jump to content

Multiple runtime terrain loaders not working in sync


berkeerem
Go to solution Solved by Bryan,

Recommended Posts

I'm trying to use multiple runtime terrain loaders to pre-load the terrains the player is about to enter. Here is how it (should) works:

  1. There is a terrain loader on Player Character. It is set to runtime with settings (Min Refresh D, Max R D, Min Refresh MS, Max R MS) as 64, 2000, 100, 1000. Regular loading ranges are 50,50,50 and all my terrains are 64x64.  No impostors.
  2. When character enters some trigger, a script enables another terrain loader in the far corner. That terrain loader is configured the same. 
  3. When character exits that trigger, the far terrain loader gets disabled.
  4. With this logic, I'm trying to trigger terrain loading 1-2 secs before I teleport my character to another terrain.

However, the second (far) terrain loader is acting weird. It begins as turned on, preventing terrain unload. Then I disable it and the terrain unloads properly. However when I turn it back on, the terrain doesn't get loaded again. I wait for 20+ seconds, keep moving the transform. For reasons I don't understand, it sometimes randomly works. Do multiple loaders create racing conditions? What's the best practice for using multiple runtime-only loaders?

Screenshot_4.jpg

Screenshot_5.jpg

Screenshot_1.jpg

Link to comment
Share on other sites

Also please let me ask this. Is there a way to cleanly force load and unload a specific TerrainScene?

Link to comment
Share on other sites

Your character should have the terrain loader attached to it. 
You shouldnt have to make your own object for this, I would recommend changing the settings of the terrain loader that is attached to your Gaia Character. 

 

Link to comment
Share on other sites

Hey @Bryan, thanks. I ditched all runtime loaders except the one on the character. Here is my problem:

My game world has many terrains but at any time about ~9 of them are loaded. Those terrains are the ones around the character and terrain loader works great for these.

I want to load a far away terrain. If I do this by playing with the terrain loader, it will load many unnecessary terrains in between the character's location and that far away terrain.

So here is what I've tried so far:

  1. I got the correct terrain from TerrainLoaderManager and forced "AddRegularReference" to the character's terrain loader.
  2. After this I've started incrementing "m_nextUpdateTimestamp" to keep it 2000 msec ahead of current time.
  3. When I wanted to unload the terrain I simply stopped incrementing "m_nextUpdateTimestamp" and let Gaia take care of the reference management. Didn't work.
  4. Then I've manually used "RemoveRegularReference" which ended up in setting "m_nextUpdateTimestamp" as 0, basically killing off the TerrainScene 🙂

I've gotta trigger loading in the remote terrain, unfortunately. If you have any other approaches I'll be glad to hear them.

Link to comment
Share on other sites

Also I have another problem. When a group of ~9 terrain load, the intersection between terrains remain weird for a couple of seconds:

  1. Check Screenshot_3 for an example of weird looking terrain intersection
  2. Screenshot_6 is what happens after ~3 seconds have passed. Smooth intersection.

Why does this happen? What can I trigger to make that delay go away?

Screenshot_3.jpg

Screenshot_6.jpg

Link to comment
Share on other sites

I should also post a solution for remote terrain loading so that the others may benefit:

private IEnumerator KeepTerrainLoadedCR()
{
    UpdateRemoteTerrains();
    AddLoaderReferenceToClosestTerrains();

    // Keep the terrain scene loaded
    while (_isKeepTerrainLoadedCRRunning)
    {
        SetNextCheckTimestampForClosesTerrains();
        // Yield and wait for the next update cycle
        yield return _waitForNextCheckHeartbeat;
    }

    yield return _waitForNextCheckHeartbeat;
    RemoveLoaderReferenceFromClosestTerrains();
}

The snippet above operates in this order:

1. An internal list of TerrainScenes gets updated using

 

_terrainLoaderManager.GetTerrainSceneAtPosition(currentCoordinate)

Every 2 seconds I call 

long currentTime = GaiaUtils.GetUnixTimestamp();
long keepLoadedDuration = terrainLoaderSettings.terrainLoaderKeepLoadedDuration;

remoteTerrainScene.m_nextUpdateTimestamp = currentTime + keepLoadedDuration;

so that the remote terrain doesn't get checked for 3 more seconds. This keeps happening so the TerrainLoaderManager skips checks for these terrains.

When I want the remote terrain to unload I simply remove reference to character's runtime terrain loader after a short delay

remoteTerrainScene.RemoveRegularReference(_characterTerrainLoaderGameObject);
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 5/27/2022 at 8:53 AM, berkeerem said:

Also I have another problem. When a group of ~9 terrain load, the intersection between terrains remain weird for a couple of seconds:

  1. Check Screenshot_3 for an example of weird looking terrain intersection
  2. Screenshot_6 is what happens after ~3 seconds have passed. Smooth intersection.

Why does this happen? What can I trigger to make that delay go away?

Screenshot_3.jpg

Screenshot_6.jpg

Hey @Bryan, thanks for the comments. How can I solve this stitching issue?

Link to comment
Share on other sites

  • Solution

image.png

If this is what you are talking about it depends on how the terrains are made to which caused this. 
Typically I see this if you are using the Unity standard terrain neighbor system. 

You would want to use the Gaia Manager - Create World - World Size and set to Custom. 
Then you can adjust your terrain tiles how many you want. 
(If this was the route you took). 

If this isnt and this happened when you stamped the world. 
I suggest adding a distance mask - and setting it to Local. 

You might be able to use the terrain stitcher tool (use low values) and see if that will stitch them together.  
This can be found in the Gaia Manager - Advanced - Tools - Terrain Stitcher. 
Make sure to save a backup before doing this though (just in case). 

 

Link to comment
Share on other sites

  • Bryan locked this topic
Guest
This topic is now closed to further replies.
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...