-
Notifications
You must be signed in to change notification settings - Fork 2
Project Structure Tips
One of the most difficult concepts of the framework to grasp is understanding how everything starts, and how everything connects together.
The short answer is - you can do everything the way you want and the way it is convenient to you. There's really no preferred way to structure your code / scenes. If you find a specific setup convenient - it's a perfect setup.
I'll try to answer a few questions that you might have. If you have a question that's not covered in the documentation - feel free to ask.
Not necessarily. This approach might actually slow down your development process, because of scene switching.
ℹ️ When I work on my games, I like to make a prefab of Master Server component and it's modules as it's children in the hierarchy. I would then add it to the main scene (the one that first opens when starting the build), and to the game scene (this allows me to automatically start master server before starting a game server, and it makes development a lot easier and more convenient.).
Yes, you can, but you will need to figure out a way to share code between them. You can also develop everything in one project, then split things when you're ready to go into production.
ℹ️ It's recommended to have everything in one project, because it's more efficient to work this way.
One build can contain code for servers and the client, but everything won't work at the same time. It's up to you to decide how you want to start the servers and the client.
You could create a special scene with buttons "Start Master Server", "Start Spawner Server" and etc., and make a special build for administrator, but it's not very convenient. And most of the time you'll want your server to run in batchmode so no UI will be visible.
When starting a server in batchmode (through command line / terminal / console and etc.), you can set a special argument, for example -startMaster. You could then setup your main scene to check if this argument is given, and start the server automatically if it is.
Example in the Demo is set up this way.
Yes, you can! This approach is great for development, or for small games.
Even if you have a special scene in which your clients connect to Master Server, authorize and do other stuff, it's great to automate this process in your game scenes, so you don't have to jump through scenes every time you want to test the game.
An example might illustrate this point better:
It wouldn't be very efficient, if every time you made a change to your game, you had to make a build, start the Master Server, start Spawner server, then start a client, connect to master server, login with your credentials, create a game, and then join the game. It sounds more like a nightmare, rather than development process!
Instead, a better approach would be to automate the whole process by:
- Adding a script to start the master server
- When master server is started, establish a client connection with it.
- Send an authentication request (login)
- Start the game server as a host,
- Register the game to master server
- Send a request to join the game.
Framework actually contains the code that does this for you, there's more info in the 🔗 Getting Started Guide.
This way, when you hit a "Play" button in the editor, you go into the game instantly, without having to go through the "preparation" steps.