itch.io is community of indie game creators and players

Devlogs

How I made a very customisable character in Live2D in Unity!

How I made a very customisable character in Live2D in Unity!

My game !Ω Factorial Omega: My Dystopian Robot Girlfriend uses Live2D for animations. A problem I encountered during the development is that I wanted to make the character very customisable. Sadly Live2D doesn't have many features which allow you to do that.

First step

First thing I've realised is that I could toggle drawables by disabling and enabling their MeshRenderer components.

    public void ToggleDrawable(string drawablename, bool value)
    {
        foreach (var drawable in Model.Drawables)
        {
            if (drawablename == drawable.Id)
            {
                drawable.GetComponent<MeshRenderer>().enabled = value;
            }
        }
    }

This allowed me to for example hide main arms and legs (Main character is a robot, so you have to acquire these), but it doesn't end there. 

Second step
    public void ToggleDrawable(string drawablename, bool value, Color color)
    {
        foreach (var drawable in Model.Drawables)
        {
            if (drawablename == drawable.Id)
            {
                drawable.GetComponent<MeshRenderer>().enabled = value;
                CubismRenderer cubismRenderer = drawable.GetComponent<CubismRenderer>();
                cubismRenderer.Color = color;
            }
        }
    }

CubismRenderer component allows you to change color of parts of the bot. So now I could disable and color parts of bot's body, but that still wasn't enough! In further updates I wanted to add clothes.

Third step
Texture atlas editor in Live2D editor

Clothes open up a lot of possibilities if it comes to modding and so I wanted to let people create their own. What I've noticed is that when you export a model to a format that unity's Live2D plugin can process, you have the ability to put textures on an atlas. The idea I came up with was to put each clothing on a separate texture. One for panties, one for socks, one for bra and so on. 

I dug into Live2D's plugin code and I found that I could use a parameter called MainTexture in the CubismRenderer class.

CubismRenderer.MainTexture = NewTexture2D;

And so I had the ability to change textures, but it was quite limited. People could change textures, but it was easy only for clothes. If someone wanted to for example make a tattoo or something along those lines they'd have to use a giant 4k texture with all parts of bot's body just to change a tiny part of it.  You could also only make clothes with a single layer, so things like striped socks with different colors that could be changed in the game weren't possible. People did made a couple interesting ones though. This is what 0.75 version of the game uses.


Final step

Because of the aforementioned shortcomings of this approach I still wasn't satisfied and so I dug deeper and thought more and finally I came up with the solution my game uses in 0.80 version of the game. The solution is creating textures at runtime. If you worked with unity before you are probably familiar with render textures. In short they are textures that you can draw to. I started my adventure by writing a shader that takes UV coordinates from the mesh of a drawable(where on the texture exported from the Live2D a drawable is) and draws it where I want to a render texture. I also created another simple shader that copied a rectangle from one texture to another.

Both of these things combined with a lot of code around it allowed me to:

In short this approach allowed me to do everything I could ever want with customisation in Live2D and it should make new mods for the 0.80 version of the game very impressive compared to the previous versions!

Learn more about the 0.80 version of the game here. It will be released on the 3rd of June in a bit over a week. If you can't wait that long it's already available for our patrons with "Early access to game releases" on Patreon and Subscribestar.

Have fun and happy headpatting!

Download !Ω Factorial Omega: My Dystopian Robot Girlfriend
Read comments (12)