It’s been 15 days since the last update, time really does fly, I have some great news and improvement and a working prototype of my next game
Two weeks ago I talked about how I wanted to make a RPG Maker like engine in Unity, the reason being that I wanted to tell a story without getting too much into technical scripts and such. I admire how it is possible to make a game without any single line of codes in RPG Maker.
Of course such a thing isn’t possible when you are working with Unity, you need to get your head around scripting at some point or another, but you can also make things so that the heavy of the code is at the beginning of the code, and thinking about one thing : level design.
For two weeks I worked on everything that RPG Maker offers in term of the basics : Dialogue system, inspection system, inventory system and something that should not be overlooked : being able to enter building and such without any loading times. I am going to talk about each and everyone of these things in details on this post
Roaming around and low loading times
One of the aspect of every RPG Maker game is how easy it is to just go indoors, outdoors, roam around ect… And it’s one of the most important aspect when you want to have a game that tells a story while keeping a certain degree of freedom, you want your character to be able to roam around the map with ease, with minimal loading times. Where RPG Maker is divided in map that can be load very fast thanks to the size of one map (On average, a map is never more than 1Mb) and the low complexity of the scenes.
In Unity things are a bit more complicated, Unity is divided in Scene, and every scene can take up to several minutes to load because of the complexity of the scene, how the engine have to seek every scripts, assets ect before loading them. In essence a scene where only three or four assets (Not included scripts) are loaded take about 3 seconds before the loading is complete.
If the player needs to wait 3 seconds every time he opens a door in the game, it discourage exploration and roaming around without any goals. So how do we solve that ? Well it’s simple, you just need to give the illusion that the game is divided in maps by simply using standalone room. Of course sometimes the game will need to be loaded sometimes, to not saturate the memory of the computer, but it’s a good solution because it offer a relatively large terrain to roam without any loading times, but it’s a good compromise between roaming around and loading times.
Dialogue and inspection system
There is two way to tell a story. A la Dark Souls by not telling a word about the story and include in the level design or through heavy dialogue. But even if Dark Souls tells a lot about his world trough it’s design, it also have dialogues to some extent. And in RPG Maker (Because it’s also one of the main things in RPGs) one of the main thing of the engine is the dialogue system.
So in Unity the way of doing that is just creating a GameController that will receive some instructions every time a dialogue is triggered, so activate an UI, made up for the dialogues, send a string to the system, block the player from moving AND interacting with the world (So that the dialogue doesn’t trigger over and over and over again).
But we still have a problem with that solution, the fact that a single string is send is a problem because the system will try to parse the whole string and will ignore the fact that the text will not fit in the box. So how do we solve this problem ? By using a special character every time we want to make a new dialogue box and storing everything is separated strings.
It’s not really easy to understand but let’s take the following screenshot
The script is put on an NPC that can talk, it will say it’s dialogue in the following order :
- I am just a test to test if the dialogue is working correctly. My name is NPC
- I like pizza and cake by the way
- My friend can’t talk, sorry about that
Here we have three separate strings stored in an array of strings. The correct string is called when needed and the engine now when to separate strings when the “@” character is written in the dialogue box, and of course it ignore the @ character. This result in a very flexible dialogue system since we don’t need to write anything else to make a dialogue and it can expand to basically an infinity of strings.
The inspection works the same and use the same function for the dialogue as the NPCs but not the same script since some NPCs will need to have a different behavior then just plain object like playing an animation.
I thought at lot about this one and I was pretty scared to tackle it since it was pretty complicated in my mind. But in the end I found an elegant solutions to have everything working correctly.
First the inventory itself is stored in a list of strings in the game controller component, and we use a list, a list is better than an array because of how flexible it is. Every time we need to add an item to the list or remove it we don’t need to “browse” the whole array to find a very particular item.
Every strings, unless if we said otherwise should only appears once in the list, to avoid conflict. When we need an item like a key we just check if the list contains in and store the result in a true or false variable, if true the list contains the item, if false it doesn’t. At this point we just need to take action if the inventory contains the item or not.
That’s what of the main three things we want to do, with the Inventory we want to add, remove and check. Fortunately, C# can do all of that in only one line. So in the end the inventory can be use by the functions in the following screenshot.
In the end, all we need is here and is very well optimize since we can’t reduce the number of lines here. And the best part is it’s basically complete for the whole game. The last thing we need to do is a way to display this inventory in the inventory screen but even that is fairly simple.
We just need to fetch everything in the list and display it in an UI created for the inventory, since it’s a string there is no additional work to display it as a text. And once again C# can fetch every strings in a list very easily without additional work in our end. The end result is an elegant, optimized way to handle the inventory.
The only thing we need to do is include a way to get object from the world, or remove object from the inventory when the player perform certain actions, for that we just need a script to add or remove a string in the inventory, and additionally to display a dialogue before the object is added.
The script in the inspector looks like this :
In these two scripts, Inv object is used to add a string to the list (In the case of adding an object) or check and remove if the object is in the inventory. Here the object that will be added or needed will be “test object”.
Notice that when an object is needed in the inventory, we cover every possibility : If the object is in the inventory, if it’s not, and what the dialogue will be after the object is already removed or added.
What’s next ?
The next thing that needs to be done is to have a correct engine and get to the level design is a saving system, being able to trigger event in an area and some additional stuff.
In the meantime, if you have any questions feel free to comment and I’ll be glad to answer them.