Location Controller
Usage
The location controller package is used to dynamically spawn and de-spawn templates to use as maps.
In short, this package allows you to create worlds dramatically larger than the limits Cratya imposes.
In short, this package allows you to create worlds dramatically larger than the limits Cratya imposes.
Instead of placing all of your creations inside of a world, Location Controller allows you to create each distinct area inside of a template. For example, a city might have a bar, hotel, house, library. Traditionally, you would model and develop all of these locations directly in the world tree. With Location Controller, The City, the Library, the House, the Hotel, and the Bar would all be individual templates. Your world tree would largely be empty, except for controllers.
Here’s how it works.
When a user interacts triggers a transportation, the Location Controller will determine whether their destination exists yet or not. If no other player is actively at this location, the template will be spawned into the world and the player will be transported there.
If there is a player at this location, the existing instance will be re-used. This means that if 10 people are inside the pizza parlor and you interact with the door, you will join them just as if the template was placed in the world statically.
Furthermore, when a player logs out, their location is saved. If the player left the game inside of the pizza parlor, then when they log back in, they will log back in inside of the pizza parlor. This will obey all of the normal rules of the Location Controller - if there are other people in the pizza parlor when the player logs back in, they’ll log back in right there next to them.
And finally, when all players leave a location, the template will be unloaded from the world.
Functionally, this means that your entity limit for the game is now uncapped, however you need to keep in mind the total entity count of all possibly spawned templates. For example, if your max player count in a game is 4, then you can spawn a maximum of 2000 entities across 4 locations. This is because each of the 4 players could be at a different location.
In practice, we’ve never surpassed 700 entities for a location. Most locations are more in the 200-400 range. If you make a rule of staying below 400 entities per location, you can support 20 players maximum. This is the case where your entity count is functionally uncapped.
Features
- Dynamically spawn and despawn locations based on activity
- Save user logout position to maintain progression in the game
- If available, uses @Mightykho’s Smooth World Settings to apply world setting locally, per location.
- Fades the screen out while building the new location
Usage
- Install the Location Controller pacakge
- Drag the following templates on to the user
a. LocalHandler
b. User Save Data
c. UserLocation
d. UserConfirmationDialog
e. ScreenFade - Drag the LocationController template into the world.
That’s it for the base setup, however we can’t do anything without creating some Locations.
Creating Locations
- Create a new template. In practice, we usually build this in the game world, and template it afterwards. We use a second World asset that’s empty except for the LocationController for the actual game, and the original world is purely for creation. I would recommend just slapping down a voxel mesh and extracting it, then templating that. This will give you a good base.
- Add the Location template to the root of the template
a. Optionally add the World Settings template to the root of the template - if this is available, it will be used to set the world settings for the client at that location. - Fill in the location Name, and set the Player template for the location
- Add a Location Spawn Point template to your location. This can be placed anywhere, it will be where new players spawn into this location. You can have as many of these as you want. Fill in the ID with a unique identifier within the Location. For example, you might have 2 spawn points: front-door, and back-door.
This is all that’s required to build a location.
Travelling between Locations
- Add a trigger or entity to your Location. Typically a door.
- Drag the Transport script onto the entity or trigger.
- Click on the transport folder, and add a new script: transportOptionScript
a. Fill in the name of the location you’re moving to, the template you want to move to, and the spawn location you want to spawn at. This spawn location is the ID you created previously.
b. You can have as many transportOptions as you want. If you have more than one, the user confirmation dialog will appear letting the player select which location to travel to. This is useful for devices such as elevators. - Click on the entity or trigger you added, add a new onInteract event, and connect it to the Entity → TransportScript → HandleInteract event.
Finishing Up
- Head back to the location controller, we need to set up the defaults. These are going to be used for the player’s initial spawn.
- Fill in the defaultLocation property with a Location you created previously
- fill in the defaultSpawnLocation with a spawn point in that location.
At this point, you should be good to go. If you preview your game, you will spawn into the default spawn template. Interacting with the door you added will transport you to the new location.
I’ve created a small demo world here that you can remix to get an idea of how it works: Crayta
Properties
You may have noticed there are a bunch of properties on the Location template that I didn’t mention. Here’s what they do.
- uniqueInstance: If this is checked, then players will not share this space. For example, maybe you’ve build an apartment template. You could mark this location as uniqueInstance, and when 4 players travel to it, they will all travel to their own unique instances of the template. They will not be able to see each other. We’ve found this particularly useful for situations where you want to load in user customizations.
- noRespawn: If this is checked, then the position won’t be saved when the player travels to this location. For example, if you move to the pizza place and then logout, you will log back in at the pizza place. If this is checked, you would instead log back in at the previous location you visited. This is useful for locations that are minigames, dungeons, etc.
- onLocationSpawn: This is an event that will be fired when the location is initially spawned. It’s provided 1 paramter: the user that initiated the spawn.