Programmer's Corner – Writing a Visual Novel Engine


Doddler here, Mangagamer’s resident programmer. Really? Really! has just released, and it’s been a really exciting project for me for a variety of reasons. It’s the second game that I’ve had to port, the first one being Tick Tack, but this time I chose to do something different. Rather than rely on an existing visual novel system like before, I made one from scratch using the Unity Game Engine. Why did I go to such extremes, and did it pay off? Well, lets take a look.

Why port the game?

Like Tick Tack before it, Really? Really! ran on a game engine developed by Navel which, while solid, had a pretty serious flaw–it doesn’t run properly on systems that don’t support Japanese text. That doesn’t impact them in their Japanese market, but it’s a serious problem for us. Sadly, Navel has already long since moved on to new releases and no longer have any of the source code we’d require to modify the engine for our needs. So how do you cope? Well, pretty much your only real option is to pack up everything and move it all over to a different, better suited engine.

So why start from scratch?

When porting a game, your primary goal is to make the game look and function as close to the original as possible. To do that, you need the right tools. For Tick Tack, I ported the game to the Kirikiri game engine, a commonly used Japanese visual novel system (you can read about that port endeavor here). But the more I looked at it, the more I figured Kirikiri may not be well suited for the job.

To understand why, you’d have to know a bit more about how most normal visual novel engine’s work. Most all visual novel games are controlled by a script, a series of text commands that control and direct what happens on screen. They are filled with commands that say when and where to display images, what text to write, basically directing everything you see on screen. The game engine reads through these scripts, and plays it back for the user as they step through the game.

But it can quickly get a little out of hand, transitioning between scenes with different backgrounds and characters is tricky business. What most games do to make this easier is implement a two-scene system. One scene is designated as the foreground (what you see when you look at the screen), and the other becomes the background (which is normally not visible). Then, through the script, you place, change, and move characters and layers on the background scene, out of view of the user. Once everything is set up correctly, the foreground scene fades away to reveal the new background scene you’ve set up. Once the transition is over, the background scene becomes the new foreground, and the sequence starts over again.

An excerpt from the Really Really script.

An excerpt from the Really Really script.

Kirikiri and Navel’s engine both use this approach, and it worked pretty well for Tick Tack. Really? Really! however expands on the functionality that was used in Tick Tack— characters move about, they bounce around, come and go from off screen, change and swap positions, and all other kinds of fun. All that happens while text types away. And here’s the issue, in Kirikiri, you can’t make any changes to the background or foreground during transitions, which includes text typing. For some effects, animations, and transitions, this is a serious issue.

Now Kirikiri is open source, so these are surmountable issues. Other companies have built onto the base functionality of Kirikiri to have it do all of these things and more. But I took a look at the future, with the D2b vs Deardrops port, which is considerably more complicated from a technical perspective, and came to the conclusion: rather than spend a lot of time rewriting parts of Kirikiri to do what I need to, I’ll do it the way I need it to work from scratch.

Unlike in Shuffle and Tick Tack, characters don't have fixed positions anymore, and they can move about on screen.

Unlike in Shuffle and Tick Tack, characters don’t have fixed positions anymore, and they can move about on screen.

How does one go about making a Visual Novel engine?

While I chose to go with the Unity engine for making my port, I’m sure there’s any number of viable options though. Most commonly I get asked why I didn’t use Ren’Py, a popular engine used in English for making visual novels. The main reason is, I don’t know Ren’Py. I do know Unity though. I’d be starting from the start, but that just means I can make each piece as I need it. This is where the fun begins.

For those unfamiliar, the Unity Engine is a modern game engine that’s really caught on among indie developers over the last couple years. It’s main draw is accessibility, speed of development, and multi-platform support. While multi-platform wasn’t our primary concern, getting something off the ground without taking a huge amount of development time was. Unity allowed me to focus almost entirely on building game relevant code, and very little time on laying groundwork systems. Even though Unity is commonly seen as a 3d game engine, any modern visual novel will use textured objects to render to the screen, it’s just cleverly done and you don’t see it when playing. Our game is no exception.

So how does one actually build the engine? Well, it’s pretty much what was said above; at the core of the game engine, you have the script interpreter. The scripts are interpreted into commands, which then communicate to specific parts of the game system. The display controller handles moving and drawing scenes and sprites. Sound commands go to a sound controller to handle audio playback. A data controller handles in game variables and save data. A UI controller handles interaction with on screen elements. And everything is tied together with a Game Controller, which handles when the script should advance, handle different waits, game states, and user input.

clip (2013-07-14 at 10.17.23)

The above image shows a relatively early version of the game being run in the unity editor. The bottom half is the game as the user sees it, but the top half gives you a behind-the-scenes look at what’s going on. The top is broken into three sections: the two scenes, the foreground and background are to the left and right sides, and the composite ‘final’ image is shown in the center. Internally, each scene is being rendered by a separate camera, and then those are being combined using a custom written shader to blend the two together. In this screenshot, the foreground is the left side, with the scene transition revealing the background on the right side using a pixelated transition mask.

Actually pretty much everything follows the foreground/background scene design, not just characters and backgrounds. Even many of the interactive elements in the game, such as the world map, the location and memory picking, they’re treated the same as any other character or background layer. I designed them as unity prefabs, collections of objects that are saved and can be instantiated at runtime, and then when you pull up the map or other similar action they’re placed into the background and a transition occurs just like any other. It’s actually pretty neat how everything works together.

Sakura, shown using the evening, nighttime, normal, *sparkling*, and monochrome filters.

Sakura, shown using the evening, nighttime, normal, *sparkling*, and monochrome filters. All use the same original sprite.

Everything in the game is built strictly to emulate the game as close as possible. Custom written pixel shaders were made to properly perform transitions and render sprites on screen properly. In Tick Tack for example, each sprite had different variations based on time of day and lighting. In Really? Really!, sprites are adjusted in real time, and so in my port I performed these effects as part of the pixel shader.

One part where I did actually take some liberty was the shattering effect that occurs when you correct one of Kaede’s memories. In the original, a shattering sound played and the screen dropped away piece by piece, but I found it very difficult to pull off that effect in Unity as I would need to do pixel-by-pixel manipulation of a texture (something that’s really slow to do). So instead, I came up with my own effect.  I used a unity asset store script “Ultimate Fracturing and Destruction” to create an object that I could apply a snapshot of the screen to, and then used the built in Unity physics to handle it falling away. That’s right, I managed to use Unity physics in a visual novel. The end result is really convincing, and runs quite well even on under-powered devices.

The screen shattering effect is actually simulated and rendered in 3D, something I can get away with only in an engine like Unity.

The screen shattering effect is actually simulated and rendered in 3D, something I can get away with only in an engine like Unity.

Some Learning Pains

Not everything went super smoothly though. I’ve you’ve paid attention to the launch, you’ll notice that it’s been patched a few times already to address various issues. That’s mostly my fault, for a bunch of reasons.  The main issue is though, is that a lot of work went into making things work, and work right, that not a lot was put into what happens when things don’t work. The most glaring issue was the game not working at all on Intel integrated graphics adapters- there were no fallback shaders present, or any real testing to see if the video adapter meets the capabilities required of the game (that has since been fixed). The game testing also didn’t uncover a lot of relatively minor bugs that I think probably should have been caught before release because the testing team usually only has to worry about quality of text and similar script related issues, rather than game engine problems.

It’s in a stable shape now though, and I still think it was successful experiment in spite of a few problems. These things I can apply going forward to make sure other releases go smoothly, starting with D2b vs Deardrops, which I’m sure will land before too long.


So that’s how I did it, the whole port done in C#/Unity, over the course of about 4-5 months. It’s been really a crazy experience, and I’m really happy to see it finally get released. It’s not without it’s own ups and downs, and I’m sure there’ll be some minor issues and pains with it, but I’m proud to have finished it, and I hope you enjoy playing it as much as I have helping to make it happen. 🙂

Update (6/12/2014)

I’ve gotten some comments about the possibility of doing multiplatform releases. The answer is, it could be possible, as the game can be made to run on different platforms. In fact, there’s secret mac and linux versions of the Really? Really! demo that were made, but never went public. There are several reasons why we elected at the moment not to do a multi-platform release.

First, we’re not as easily able to support issues on other platforms if they come up, and it also greatly increases the complexity of patching different versions of the game. I’m pretty much the only staff member that would be able to troubleshoot or support those problems, which is a bit of an issue because I’m not a confident mac or ubuntu user. Second, we couldn’t find a way to meet our contractual obligations with our clients to provide DRM on multi-platform versions of the game. That sounds a bit silly, I’m somewhat anti-DRM myself, but we have an obligation to our client in our contracts to put some form of protection in place. And thirdly, a fairly minor thing, but our website doesn’t at the moment support different downloads for the same product, so distribution became a problem. This game is also a sequel of sorts to a windows only game, so it doesn’t make a lot of sense to go multi-platform here. It’s perhaps not much solace, but I’ve heard reports that the full game runs well in VirtualBox and VMWare, and possibly even on Wine as well. It is something we’re keeping open to, and in the future may do multiplatform releases if it’s possible.

If you did want to try the cross-platform demos that were made, you can grab the mac and linux versions below. They’re older versions of the game, so they could contain bugs that were fixed by release, but if you want you can give it a shot!

Really Really Mac Demo / Really Really Linux Demo

Bookmark the permalink.


  1. Kudos and many thanks to you for all this hard work

  2. Fantastic blog post as always Doddler. Thank you for your work to help MangaGamer have an engine available to handle the advanced effects the Japanese developers are using with their own engines. Here’s to smoother releases in the future.

    Thanks also for identifying yourself. I’d like it if all the blog posts identified the author.

    I’ve worked for several software companies and I don’t think any of them have ever lost more than a single day’s worth of code. I am always surprised how often it seems like the Japanese companies lose programming assets, like source code.

    • It’s very, very common in this industry for companies to outsource a large volume of the work. There are some companies where nearly every aspect of game development is sourced externally- and they aren’t always diligent in tracking down those resources after a project is over.

      • Thank you. That is interesting and somewhat odd to me that they do it like that. But it explains everything.

        I hope there aren’t other things that are different from Clock Up’s depiction of an eroge company. 🙂

  3. Great article. Actually, I was really curious about the reasons why Kirikiri was dropped and replaced by Unity since a full 3D engine framework for a simple VN seemed a bit like overkill (The last time I had to program a pixel shader was for area reflection on a spherical object years ago). However, when I saw the characters in Really? Really! moving around like crazy I had a guess.
    Future VN ports will probably profit a lot from the work that went into this new engine. Maybe you should reconsider releasing high resolution versions for the VN’s since the engine is certainly fast enough for it. Could also get interesting for potential new gameplay titles from Eushully maybe?! 😉

  4. That’s pretty cool Doddler, now that mangagamer had a engine en unity, are there plans to port the games to Linux/Mac? because that would be awesome

  5. Man, seriously great work Doddler. That sounds like it had the potential to be a really stressful 4–5 months…

    Completely agree with shogoki_vnz. It would be really great if we could see Really? Really! on OS X and Linux now that it’s running on Unity.


  6. Darn… looks like the commenting system stripped the last character in my comment (U+1F609 WINKING FACE—an emoji), probably because it can only handle characters in Unicode’s Basic Multilingual Plane (BMP) (U+1F609 being one in the Supplementary Multilingual Plane (SMP)).

  7. Phantom Thief 1412

    As a programmer myself, this is a nice look at the technical side. Used Unity’s 3D to create 2D games before and it does help with certain things. Hope to see this engine get worked on more for the future, maybe even becoming the default ported engine for Mangagamer?

  8. Very interesting.

  9. Which version of Unity are you using?

  10. For this game, how many man-hours were put into porting the engine vs. translation and editing?

  11. As a developer myself, this is really interesting! I have just one question, do you have any play to release the engine as an opensource project? Aside from satisfying my own curiosity, a unity-based visual novel engine would be a tremendous contributing to the community!

    • I’m considering releasing the source, but I think it would be best just for curiosity sake, since the engine is designed for a very specific use case, which is running an existing game, it’s probably not well suited for working on an original game. I’m also not convinced it’s very good code either, as my first attempt it’s a pretty big mess! Still, if I can get approval I will try to release it.

  12. *clap clap clap* Wow… reading this is awe-inspiring of your hard work and dedication. It makes me feel like learning a programming language.

  13. You say you don’t know Ren’py, it’s literally wrapped python. As soon as you mentioned cameras in unity, I automatically thought of the lack of them (for the most part) in Ren’py.

    However, I have no idea how you’d do the shatter effect in Ren’py. It’d most likely require an external Python library.

    However there’s a sense of pot-kettle-black here as I don’t know unity. So after reading this, it may be worth looking at for a VN project I’m planning myself, although I’ll probably still use Ren’py for some rapid prototyping

  14. Mama mia. Read this really gave me a strong impresion of how hard is to localize japanese games in english. At the first that it was more about learn how it worls and change the text into english when the translator finished their work and maybe using a program to make them compatibles with operative sistems in english. Now i see that is like make the whole game from the very begining with the fundamental resourses.

    I hope that more people read this and buy Mg games instade of pirate them.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.