Game
After Sanctuary

2 months ago

Devlog #2

World streaming.


Hello Sanctuary seekers,

I thought I'd kick off the devlogs.
I'll be posting here by telling you a little bit about my world streaming.

This is aimed more at fellow developers who may want to do something similar and players who sometimes wonder how the funk this stuff works.

There will be code snippets but I'm not going to share the whole thing.
I don't believe it would be any good to anyone else as full code as it's integrated with my game for my specific use case.

The world is 8km by 8km (currently).
It's made up of a grid of terrain tiles.
I have a development scene where I can edit the terrain, place gameobjects and basically create the world.

When I want to test, I fire off my editor script which collects all the terrain tiles, gameobjects and anything else and packages them all into seperate scenes.

menu.png

It also creates a JSON file which holds information about each scene.

json.png

This is what the SceneStreamer class uses to load and unload these scenes around the player as he/she moves through the world.

I can then load into my test scene which contains the SceneStreamer and other game logic type stuff amongst other things and I can play through the game.

Inside the SceneStreamer, we create a dictionary to hold the data in the JSON file in memory, otherwise We would be grabbing the scenes path from disk each time they are required (not slow but higher cost).

dict.png

We load in the tile meta data

loaddata.png

and populate the dictionary.

buildindex.png

We start a coroutine to load the initial scenes, passing in the spawn position of the player from the PlayerSpawner class.

pos.png

At the moment, this loads the player to a random POI. Sounds stupid but I only have 1 POI in the list atm.
I'll probably never use the random POI spawn but it's there if I need to.

Once the initial tiles have loaded around the POI, the scene streamer fires off an event action to let other classes know the game world has loaded.
We also start the scene streaming loop.

event.png

The player spawner listens for this event and spawns the player.
It also fires off it's own event to notify other classes which depend on the player being active in the scene before they can work.

spawnplayer.png

We also register the player with the scene streamer properly so it knows where we are in the world and how far away from origin.
If we get too far away, everything is shifted closer to the origin to avoid floating point calculation errors.
Anything > 3k unity meters from 0,0,0 is ropey at best and glitching happens because the floating point calculations become inaccurate.

The scene streamer looks for movement and also runs on a timer. but only if the player is moving.

scan.png

It then happily loads and unloads the world around the player.
This is just the basics really, it does other stuff like loading game objects and AI in over time instead of trying to do it all in one frame.
The real cost with activating game objects is the physics so this has to be done carefully otherwise the player will get stutters so I limit the max activations per frame.

activperframe.png

This keeps everything running smooth.
The streaming class also assists with loading into indoor scenes and back out of them into the open world.

I'll probably post more about that in the future.
If you have any questions please feel free to post them in the comments.

Don't forget to join us on discord https://discord.gg/S8cCdyzB

Until next time,

Stay safe.



0 comments

Loading...

Next up

Today I was setting up the location of the first boss. His name is "Father" and he is the first of the Patagonians. His task is to guard the road to the House.🛡🗡 Bookmark pre-launch page🔖🔖🔖

https://www.kickstarter.com/projects/rdvindiegame/the-patagonian…

I have added rewards for quests so that villagers can give you something in return for your hard work helping them. 🥳

I want to know - what's your favourite quest reward?

"Our work is never over" they said.

Sometimes the suction cup get sticky. Small animation I made in Blender after doing my tutorial on picking up/dropping objects in animations. Crate model by jQueary (https://sketchfab.com/3d-models/game-ready-sci-fi-crate-d98deca6…).

Levels' maps.

Coming Soon...

blender animation experimentation, getting the hang of things fast. arms, rig, & gun models by me ofc

Super Sonic Pixel art.

Hey you, rookie! Yes, I am talking to you!! Come over here? Relax! Just stick to me and everything will be fine. By the way, my name is James Varhuher, but you can call me Big J. I will bring you up to speed.

What Are You Doing In My Swamp!?

Now spruce forest monsters can vomit forest shields, but Brutal Castle will not stop!

#gamedev #pixelart #indie