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.

Example mod made by changing the texture


Texture used for socks in this mod
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:

  • Create textures for modding which only have the drawables they want to edit and allowing modders to edit not only clothes, but all parts of the bot!

    Example texture from an automatically generated mod that only affects eye
  • Draw multiple times using different textures as a source texture. Effectively making it possible for drawables to have layers. 
    • With this I could make things such as sneakers with different colors on every layer at runtime.
      Different random colors of sneakers found in the shop.
    • I could add textures on top of default ones. This is what allows modders to create tattoos, piercings or jewlery.
       
      Womb tattoo mod for 0.80
  • Makes performance better. This approach doesn't need every clothing to have a separate texture. In short less textures = less texture swapping = better performance.
  • Draw textures on top such as scratches which display how used bot's parts are.
    Scratches on bot's arm

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!

Get !Ω Factorial Omega: My Dystopian Robot Girlfriend

Download NowName your own price

Comments

Log in with itch.io to leave a comment.

Thanks for sharing. I've been curious about this for a while, it's called live2d but is this what creates that effect of customisable 3d characters like how is evident in the missionary pose?

I saw it in some other games too and I've been curious about the development that goes into it for a while.

(+1)

what os and studio so you use? Im a linux user, at the moment specifically SparkyLinux, regardless its always debian based. I'm interested in working on some of this on my free time.


so pretty much I'd like to know the set up you work with to see if its for me, if that's kool.

(1 edit)

Will it have BJ in the next version @@

P/S:this is a really great game can't image how much time you put in this game 

Really cool to see a dev talk about the compromises needed to make something like this possible. Totally didn't expect to see that Live2D was the basis for this project, really interesting read!

(+1)(-1)

Poggy woggies

(-1)

Cool

(+10)(-1)

It's crazy to know how much work goes behind this project! Take your time with everything, because you're doing fantastic!

(+4)(-1)

Thanks!

(+1)

Hentai Haven Chan Mod going to work in v.80? Or is it going to get updated? I tried mods for the 1st time last week and it was the 1st one I picked

(+3)

It might get updated. Give modders some time!

(+4)(-1)

Wow... Yeah you're going places that is for sure! Glad you are on the project.

(+2)(-1)

Thanks!