Jump to content

Gaia - Assigning Instantiated Objects To a Terrain


cflorida98

Recommended Posts

Hello, I have setup Gaia and I am using the Terrain Loading. During runtime I instantiate the player and some enemy's.

My issue: The player and enemy's are spawned in and can walk on the terrain, but they are not assigned to the terrain they are on (They are just in the main scene). Now I am not sure if I need to do something special, or if I have to maybe RayCast to get the terrain and manually assign them?

 

image.png.5e0f63b4fc3af73faada74350f773a2f.png

Link to comment
Share on other sites

Hi @cflorida98,

please note that this is less an issue with Gaia, but more default behavior of Unity: When you work with multiple scenes, one scene is the "Active Scene", you can see in the scene hierarchy that one scene name is printed in bold lettering. That is the current "Active Scene". If you instantiate an object from code, this object will end up at the root of the current active scene unless you move it to the desired scene / reparent it afterwards.
So you would need to set the scene of the spawned player object to the desired target scene and reparent the transform under the terrain transform.
- BUT - 
usually you would rather want the player to be in the main scene, because you would otherwise need to constantly track on which terrain they are, and then as soon as they move from one terrain to the other swap the scene and reparent them to a different terrain. If you do not do that, the player would eventually disappear when the terrain they are "assigned on" initially gets unloaded.
So unless there is a really good reason I would keep all dynamic, terrain-traveling objects in the main scene.

Link to comment
Share on other sites

Hey @Peter,

I apricate your response, it was very helpful. I do however have an additional question based from this, "So unless there is a really good reason I would keep all dynamic, terrain-traveling objects in the main scene."

I have enemy spawning on a networked game, so I figured I would move the enemy's to the terrain they are spawned on, so other player will not be bogged down by 200 enemy's when there are only 30 apart of their terrain. I have already figured out how to do this, but would this be an example of a "really good reason"?

 

As you have kinda mentioned  this, I do have to run checks for if player is in bounds of terrain, store synced variables for the terrain names to identify where to move the zombies to for newer clients, etc etc.

Link to comment
Share on other sites

On 12/1/2023 at 6:45 PM, cflorida98 said:

have enemy spawning on a networked game, so I figured I would move the enemy's to the terrain they are spawned on, so other player will not be bogged down by 200 enemy's when there are only 30 apart of their terrain. I have already figured out how to do this, but would this be an example of a "really good reason"?

In general it makes sense to make it so that each client only needs to render the enemies the player can see. However when you move the enemy to the terrain that they are spawned on, I'm not sure if this will automatically solve this network culling task for you.
For example if player A is standing on terrain 1, and an enemy E spawns there, you could assign that enemy to terrain 1.
If player B is on terrain 14, far away from terrain 1, he would not have terrain 1 loaded in. If E is networked, I'm not 100% sure how unity would react if you would take E and put its transform under an object that player B's client does not know about. My sense is this might create an error, or still leave E visible for B because this reparenting could not be mirrored for the client.
But it could be that you solved all this in your networking code already.

The important takeaway is: The gaia terrains are loaded in as additive scenes, and you should be able to interact with them in a networked game the exact same way if Gaia was not part of the project, and you created a games with multiple additive scenes yourself. If re-parenting the objects to terrains and putting them into different scenes helps for your project and works well, then you can do it, but it should not automatically solve networking issues for you

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
  • 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...