To see uMMORPG 2D in action, simply open the included scene from uMMORPG/Scenes, press Play in the Editor and select Server & Play. Run around a bit, kill some monsters, pick up some new items and try some quests.
Once you got a feeling for it, now it’s time to get some basic project overview and learn some new stuff. Recommended first steps:
Right now, the recommended Unity version is Unity 2018.2.20. You should not use an older version because Unity is not downwards compatible.
You can use newer versions at your own risk. uMMORPG is a big project that uses a lot of different Unity features, so whenever Unity introduces a new bug, we feel the effect very significantly. In theory, any newer Unity version should work fine if (and only if) Unity didn’t introduce new bugs. That being said, it’s common knowledge that Unity always introduces new bugs to new versions.
During the past few years working on uMMORPG, the process was to download Unity, encounter bugs, report them, upgrade Unity to the newer version where the bugs were fixed, only to encounter new bugs, and so on. It was a never ending cycle of upgrading headaches, with only the occasional stable version in between.
During GDC 2018, Unity announced the LTS release cycle. LTS stands for long term support. Unity LTS versions are supported for 2 years and will only receive bug fixes, without introducing any new features (and hence new bugs).
Words can hardly express how significant LTS versions are for a multiplayer game. You should absolutely use LTS at all times, otherwise your players will suffer from bugs and all hell will break loose.
The Player prefab(s) can be found in the Prefabs/Entities/Players folder:
Players have several components attached to them, with the ‘Player’ component being the most important one.
You can modify a whole lot without writing any code, simply browse through the Player component in the Inspector to get a feel for it.
You can of course add your own components to player prefabs too.
Players move on Unity’s NavMesh with their NavMeshAgent component.
If you want to create another player type, simply drag the existing player prefab into the scene, modify it to your needs, rename it and then drag it back into the folder to save it as a different prefab.
Modifying the existing prefab step by step is always a lot easier than creating it all from scratch again.
Make sure to also drag the new prefab into the NetworkManager’s spawnable prefabs list. uMMORPG will then automatically display it as another option in the character creation menu.
Each player has a maximum level property that you can modify to set the level cap:
Player stats like health, mana, damage, etc. are level based. They start with a base value and add a bonus for each level:
For example, a level 1 player has 100 health. A level 2 player has 100+10=110 health. A level 3 player has 100+20 =120 health.
Level based stats are a great solution, because they scale with any level cap. If you decide to raise the level cap from 60 to 70 in your game, then all you have to do is modify the MaxLevel property. Health, mana, etc. will scale to 70 automatically.
uMMORPG comes with a party feature, which allows players to form groups and kill monsters together. Being in a party grants players an experience boost and allows them to share experience among each other.
A player can invite another player to a party by standing close to the other player, targeting him and then pressing the Party Invite button in the Target UI:
The party owner can then modify the party settings in the Party UI window.
uMMORPG comes with a guild feature.
A player can create a guild by talking to the Npc:
A player can invite another player to a guild by standing close to the other player, targeting him and then pressing the Guild Invite button in the Target UI:
The guild master can then modify the guild settings in the Guild UI window.
The Monsters can be found in Prefabs/Entities/Monsters:
You can modify it to your needs, just like the Player prefab.
There is no complicated spawning system for monsters. Simply drag them into the scene and position them wherever you want them to live.
Monsters have a simple AI and they need to be able to navigate around obstacles, for example to follow a player into a building. This is very difficult to do, but thanks to Navigation2D, all we have to do is set the Monster’s NavMeshAgent2D.destination property.
So in other words, Monsters are NavMeshAgents on Unity’s Navmesh. Make sure to rebake the Navmesh whenever you modify the game world.
Monsters are driven by a Finite State Machine(FSM) in the Monster.cs script. The behaviour is 100% code, so you’ll have to modify the script if you want to change it.
Note: there’s no easier way to do it with UNET at the moment, and it does work really well too.
uMMORPG has Spawn and Respawn positions:
Spawn positions are where the player classes spawn after creating their character.
Respawn positions are where the player classes respawn after death.
You can add more Respawn positions by duplicating the existing one, afterwards move it wherever you want. A player always respawns at the closest respawn position.
uMMORPG uses a small and simple scene to display all of the features. You can of course add any sprites or environment assets that you like. Simply make sure that:
Adding a new Skill is very easy. We can right click the Resources/Skills folder in the Project Area (as seen above) and select Create->uMMORPG Skill to create one of several existing skill types. Now we rename it to something like “Strong Attack”. Afterwards we can select it in the Project Area and the modify the skill’s properties in the Inspector. It’s usually a good idea to find a similar existing skill in the same folder and then copy the properties.
Afterwards we select the player prefab and then drag our new skill into the Skill Templates list to make sure that the player can learn it.
Note: uMMORPG uses scriptable skills and you can create any new skill type if necessary. Take a look at Scripts/SkillTemplates to learn how the existing skills were implemented.
We already added the most basic items types, so you can simply duplicate existing items to make similar ones:
You can also create new Items by right clicking in the Project area to select Create->uMMORPG Item:
As you can see, there are already different item usage mechanisms. Potions like the Health Potion will be consumed to increase health and mana. Other items like the Sun Bow do none of that, but shoot arrows instead. Every MMORPG will need all kinds of different item usage mechanisms, which is why we implemented Scriptable Items (aka ItemTemplates):
Please take look at the Scripts/ItemTemplate.cs file and the Scripts/ItemTemplates folder with the currently implemented Scriptable Item types. In most cases, you will want to inherit from UsableItemTemplate.cs. All you have to do is overwrite the .Use() function (and a few others depending on your needs) to add any item mechanism that you want. You could have an item that kills every Monster on the server in .Use() or levels up all guild members. The possibilities are endless.
To create a new Scriptable Item type, simply create a new Script, inherit from ItemTemplate (or UsableItemTemplate if it’s supposed to be usable) and then add your logic / properties as needed. Make sure to add a menu entry like this:
So that you can create an item of that type via right click.
We just talked about ScriptableItem.cs, which is the true ‘Item’ class in uMMORPG. But there is also Item.cs - what the hell?
uMMORPG uses UNET’s SyncListStructs for the inventory and the equipment. Those SyncListStructs only work with structs, so we can’t put ItemTemplate types in there. And that’s a good thing, here is why:
Note that all ‘dynamic’ Item properties like the pet’s level are also in Item.cs - since two Items of the same ItemTemplate type might as well have different pet levels.
There is also the ItemSlot struct, which is just Item + amount. No magic here.
The Inventory and Equipment SyncListStructs work with ItemSlots.
A slot contains a valid .item if the .amount > 0. If .amount == 0 then the .item is invalid and should not be accessed.
Let’s say you want to add a Strong Health Potion to your game. Here is the step by step guide:
Now press Play, find your item and use it!
2D equipment is simply a sprite that is put on top of the character sprite. Take a look at the existing sword sprite sheet to see how it consists of additional sword parts on top of the attack animation.
Make sure that the separate sword slices for each animation frame have the exact same name as the character slices. So for example, walk_right_0, walk_right_1 etc.
Afterwards drag all the slices into an equipment item’s sprites property:
uMMORPG comes with a simple quest system. Quests can be found in the Resources/Quests folder:
To add more quests, simply duplicate an existing one and modify it to your needs. Afterwards drag it into an Npc’s available quests list:
Crafting recipes can be found in the Resources/Recipes folder:
Recipes are very simple. They have a list with ingredients and a result item:
You can craft them ingame by dragging the ingredients into the crafting slots, afterwards the item that can be crafted will appear:
This system also allows for real recipe items. For example, the Vigor Potion could also require a secret scroll that players need to find in order to craft it. The scroll can simply be added as one of the ingredients.
First of all, we have to understand that the game server can only handle one Scene right now, so our whole game world should be in that Scene. If you want to replace the current Scene, you can either just build on top of it or duplicate it and then modify what you want to modify.
Note: I created an experimental(!) NetworkZones addon that allows us to use one different scene per server process, with portals to move between them. The addon is pinned in our Discord server’s verified channel.
uMMORPG uses SQLITE for the database. SQLITE is like MySQL, but all stored in a single file. There’s no need for a database server or any setup at all, uMMORPG automatically creates the Database.sqlite file when the server is started.
SQLITE and MySQL are very similar, so you could modify the Database.cs script to work with MYSQL if needed.
Note that SQLITE is more than capable though. Read the SQLITE Wikipedia entry to understand why.
The database can be found in the project folder, it has the name Database.sqlite.
The database structure is very simple, it contains a few tables for characters and accounts. They can be modified with just about any SQLite browser and we listed several good options in the comments of the Database script.
Characters can be moved to a different account by simply modifying their ‘account’ property in the database.
A character can be deleted by setting the ‘deleted’ property to 1 and can be restored by setting it to 0 again. This is very useful in case someone accidentally deleted their character.
uSurvival uses Unity’s new UI system. Please read through the UI manual first:
Modifying the UI is very easy. Just modify it in the Scene in 2D view.
Most of the UI elements have UI components attached to them. There is no magic here, they usually just find the local player and display his stats in a UI element.
Feel free to modify all the UI to your needs.
uMMORPG has a built in Item Mall that can be used to sell items for real world money. The system is very simple to use:
Note: you can also process new orders manually and add them to the character_orders table by hand.
uMMORPG’s NetworkManager has a Server List:
The default entry is for a local server on your own computer, so you can test multiplayer easily. If you want to host uMMORPG on the internet, you can add another entry here with some name and the server’s IP. Players can then select it in the Login screen:
UNET puts the server and the client into one project by default, so any build can run as client or server as necessary. There is no special build process needed.
It’s obviously a bad idea to host the server on a mobile device or in WebGL of course, it should be a standalone platform like Windows/Mac/Linux with some decent hardware.
The recommended server platform is Linux. Unity can create a headless build of your game there, so that no rendering happens at all. This is great for performance.
Linux is the recommended Server system. If you have no idea how to get started hosting a UNET game on a Linux system or where and which one to even rent, then please go through my UNET Server hosting tutorial for a step by step guide and then continue reading here.
If you already know your way around the Terminal, then use the following commands:
Upload Headless build to home directory:
scp /path/to/headless.zip email@example.com:~/headless.zip
Login via ssh:
Install 32 bit support (just in case), sqlite, unzip:
sudo dpkg --add-architecture i386
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo apt-get install libsqlite3-0:i386
sudo apt-get install unzip
Unzip the headless build:
Run the server with Log messages shown in the terminal:
./uMMORPG.x86_64 -logfile /dev/stdout
The whole point of UNET was to have all the server and client source code in one project. This seems counter-intuitive at first, but that’s the part that saves us years of work. Where we previously needed 50.000 lines of code or more, we only need 5000 lines now because the server and the client share 90% of it.
The 10% of the code that are only for the server are mostly commands. Reverse engineering the client could make this code visible to interested eyes, and some developers are concerned about that.
The first thing to keep in mind is that this does not matter as long as the server validates all the input correctly. Seeing the source code of a command doesn’t make hacking that much easier, since for most commands it’s pretty obvious what the code would do anyway. For example, the Linux operating system is very secure, even though it’s code is fully open source.
Furthermore it’s usually a good idea for game developers to spend all of their efforts on the gameplay to make the best game possible, without worrying about DRM or code obfuscation too much. That being said, if you still want to hide some of the server’s code from clients, you could wrap your [Command]s like this:
And then #define SERVER in your code before building your server.
uMMORPG comes with a very powerful Addon system that allows you to add functionality without modifying the core files. It’s also useful to share features with the community.
An example addon script can be found in the Addons folder:
The example script shows you which functions you can use and which classes you can extend.
There are a lot more features and improvements planned for uMMORPG. If you want to update your local version to the latest version, you should keep a few things in mind: