Jump to content

Terrains not attaching (in my automation scripting)


Sorra the Orc
 Share

Go to solution Solved by Sorra the Orc,

Recommended Posts

First off, this is NOT a bug in Gaia. I am trying to do something that is not by design in the current API. That said, I am so close to having it working I would appreciate some help. First, the use case:

I want to generate large numbers of islands automatically, in the editor (not at runtime), The idea is that I provide some ranges for randomization of the World Designer and then set my editor script running in a loop. Each terrain will be saved into a prototype folder ready for review.

I have successfully created a terrain this way and it saves just fine. All good so far.

My problem is that if I run a generation of more than one terrain in a loop only the last one is correctly saved. Every scene before the last one will look fine in terms of scene structure (Gaia Runtime and tools are there, session manager shows the operations, water, lighting etc. is all present). However, Terrain Data is missing.

It would seem that there is some operation that finalizes the terrain data that is happening automatically when my code releases control. Any idea what it is?

Another thing that I'd like to resolve, and it may be related, is that my scenes have a "Temp Session Tools" object under the Gaia Tools object, they have children relating to biome stamping. This appears in both the complete and broken scenes.

 

Link to comment
Share on other sites

I figured some psuedo code would help think about this (I can share the actual code if helpful - I'll be open sourcing it eventually)
 

  1. Generate a new Scene
  2. Add Gaia components using the GaiaAPI
  3. Randomize the World Designer based on my criteria
  4. Built the terrain (multiple tiles in a single scene)... NOTE: I didn't find an API to do this so I adapted code from your Editor code - this is likely where the problem lies.
  5. Apply the biome
  6. Add Runtime
  7. Save the scene
  8. If more scenes to create repeat from 1.

The last scene saved will be correct, regardless of how many scenes I generate. If I generate >1 then ONLY the last scene is correct. All other scenes have missing terrain data, but otherwise look the same).

Link to comment
Share on other sites

Hmm, the first thing that comes to mind is that the terrain data object needs to be stored as a proper asset file in the project hierarchy. If it is not, I would expect the terrains to "loose their data" afterwards as soon as the scene is closed. You could compare your code to build the terrains to the "CreateTile" function in GaiaSessionManager.cs.
Another thing I could think of is that you need to call Terrain.Flush() when you are done with your changes, however when the biome is being spawned that should be called by Gaia already at some point.

Link to comment
Share on other sites

Interesting, I've traced the code and it is calling `CreateTile` to do the donkey work. In that method I see the Terrain data being saved to the asset database. However, for all but the last terrains these are a splatmap rather than a Terrain Data. I tried adding a Terrain.Flush() into the process, but no difference.

This is the data saved in the name of the first (broken) terrain:
image.png.df5f79e8f9baf2f6a5d2dc9c5ef8b31b.pngimage.png.5d45532dfef1c2e628d5ea01ebc3e439.png

And this is the data from the second (working) terrain:
image.png.1c96b084d901d6e889b00dd180fb51d0.pngimage.png.b6f2165732209c3f69c094175ad9bd77.png

 

They appear to be the same flow through the code, but clearly something is different. I'll keep looking but if anything comes to mind please give me a nudge.

image.png

Edited by Sorra the Orc
Remove unnecessary image (again)
Link to comment
Share on other sites

🤔 Hmmmm it looks to me like the first broken data object is just the empty splatmap, but strangely the splatmap image (which should be a child of the data object) has taken on the position of the data object somehow....
Could it be that maybe the terrain data object gets re-used instead that a new, independent terrain data object is being created? I think something like this could be going on:

1. New terrain data object is being created in memory
2. Terrain data object is being stored as asset in the project hierarchy in a certain location A
3. The same terrain data object (that still points to the asset in hierarchy) is being repurposed for the next terrain
4. same object is now stored in a different location B - the file in location A vanishes, leaving only the splatmap behind in this location. I could imagine there is some mechanism in place for such nested objects in the unity logic where the child becomes the parent if the parent is null.

Link to comment
Share on other sites

Thank you for the pointers. I'll take a look at this today. I *think* I'm creating new terrain data objects. But I'm reusing as much of your code as I can so it's possible I missed something important that refreshed the terrain data between scenes.

I appreciate you taking the time to help me figure this out. The (to be open sourced) code is progressing nicely and I think it will be a useful addition for those of your customers who need to generate alot of terrains. I now have it rendering a fly around for initial review. My thinking is artists would look for a terrain that is "close enough" to what they need, then drop in and edit it to be a playable level.

 

I just posted some example fly arounds on Discord (file size limit here) generated completely unattended (other than hitting "Generate"). See https://discord.com/channels/423247963457060866/426833964737495050/926179265345622086

Gaia Pro is awesome!

Edited by Sorra the Orc
Reposted to the right discord and changed the link
  • Like 1
Link to comment
Share on other sites

I think I have figured it out, but I'm still testing. It looks like what is I'm spawning the biome then immediately saving the terrain.  This appears to be causing a race condition. I'm not 100% certain of this as I'm still unravelling the spawn code. But it feels right.

I can't seem to find an event to subscribe to upon completion of the spawn operation. Any pointers as to how to solve this?

My current spawn code is copied from your UI code:

Spawner.HandleAutoSpawnerStack(biomeController.m_autoSpawners.FindAll(x => x != null && x.isActive == true), biomeController.transform, range, worldSpawn, biomeController.m_settings);

 

Edited by Sorra the Orc
Link to comment
Share on other sites

13 minutes ago, Sorra the Orc said:

I can't seem to find an event to subscribe to upon completion of the spawn operation. Any pointers as to how to solve this?

You can subscribe to the "SpawnFinishedCallback" of the first spawner in the stack. The first parameter of the "HandleAutoSpawnerStack" function is a list of AutoSpawners, this here should work:
 

 List<AutoSpawner> spawnerList = m_biomeController.m_autoSpawners.FindAll(x => x != null && x.isActive == true);
 spawnerList[0].spawner.OnSpawnFinished += <YourMethodHere>();
 Spawner.HandleAutoSpawnerStack(spawnerList, m_biomeController.transform, range, worldSpawn, m_biomeController.m_settings);

 

Link to comment
Share on other sites

  • Solution

OK.. it was none of those things. It was stupid programmer error. I spent so long learning how Gaia was doing its thing that I became convinced I had done something wrong in unravelling your code. But the problem was much simpler...

I was creating a new scene on the creation of the first terrain only. Subsequent terrains were therefore being created in that same scene. However, the scene was being saved with a different name. This meant that the original references to terrain data were now cross-scene references and thus being lost.

Thank you again for trying to figure this one out. Each one of your suggestions seemed to make sense as I dug into your code exploring how it worked. As a result I now know quite alot about how the Gaia stamping system works. That can only be good for future work.

Now I will start to polish the code and get it out there.

  • Like 1
Link to comment
Share on other sites

Glad that you found the solution! I would not have thought of a cross scene reference having an effect like that, I would expect the terrain to lose the connection / reference to the terrain data object, but I would not expect the terrain data object to be in that corrupted state after. Thanks for sharing the solution!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Tell a friend

    Love Unity 3D World & Game Creation Tools - Canopy - Procedural Worlds? Tell a friend!
  • Interesting Articles

    1. 2

      I'm getting tired of doing islands and craters

    2. 2

      I'm getting tired of doing islands and craters

    3. 1

      Problems with latest Gaia Update

    4. 1

      Adding shoreline or waterline effects, beaches, river banks, etc.

    5. 1

      Just upgraded my Canopy to Pro

×
×
  • Create New...