Dear Users,

Now, we are seeking users who can give us a hand with expertise to evolve our software more dynamically.
If you are willing to help us, we’d like you to make a registration for “Live2D Creators Circle” via the link below.
Designers, programmers, translators are especially welcomed so far.
(More detailed explanation will be given to you before we ask you to do tasks)

https://docs.google.com/forms/d/1G5KK_GL3ozwPXtTHrpi_ktbsI8UZf8jlYRSlDworyBo/viewform?usp=send_form

How do I reference the model from a script?

Is there any way I can reference a Live2D model within a script instead of modifying it inside LAppModel.cs, for example?
I tried public Live2DModelUnity live2dmodel; but it always returns as null.

Comments

  • The L2DBaseModel class, from which the LAppModel class should be inheriting, has a getLive2DModel() method which returns the Live2D model instance once the moc has been loaded. Did you give that method a try?
  • edited July 2016
    I haven't, just tried it out but it still returns as Null... not sure what did I do wrong here.

    using live2d;
    using live2d.framework;
    using System.Collections;
    using System.Collections.Generic;

    using UnityEngine;
    public class PrintHandPosition : MonoBehaviour
    {
    L2DBaseModel lappmodel = new L2DBaseModel();

    // Update is called once per frame
    private void Update()
    {
    var l2dmodel = lappmodel.getLive2DModel();
    Debug.Log(l2dmodel);
    }
    }

    I want to control my model motion parameter from a script, if you can help me write the snippet of the code for that (without modifying any files from Sample1App) it would be much appreciated!
  • Still looking for answer...
  • Hey, sorry for answering late. The below isn't tested but hopefully works. (let me know if not). The currently easiest way to do this if you don't want to do the loading completely on your own is to initialize a 'LAppModelProxy' component and then access the Live2D model through that. I hope this allows you to achieve what you want to.
    using live2d;
    using live2d.framework;
    using UnityEngine;
    
    // Require a 'LAppModelProxy' component to be available
    // (making sure to set the proxy up in the inspector).
    [RequireComponent(typeof(LAppModelProxy))]
    public class PrintHandPosition : MonoBehaviour
    {
        private LAppModelProxy _proxy;
    
    
        private void Update()
        {
            if (proxy == null)
            {
                proxy = GetComponent<LAppModelProxy>();
            }
    
    
            var model = proxy
                .GetModel()
                .getLive2DModel();
    
    
            Debug.Log(model);
        }
    }
  • edited July 2016
    Got it, I made it work now the value returns as Live2DModelUnity :)

    However I still can't get setParamFloat to work, could you see what did I do wrong here?:
    using live2d; using live2d.framework; using System.Collections; using System.Collections.Generic; using UnityEngine; public class PrintHandPosition : MonoBehaviour { private L2DBaseModel l2dbasemodel; private LAppModelProxy _proxy; private ALive2DModel themodel; // Use this for initialization void Start() { if (_proxy == null) { _proxy = GameObject.Find("Live2D_Canvas").GetComponent<LAppModelProxy>(); } var model = _proxy.GetModel(); themodel = model.getLive2DModel(); } // Update is called once per frame private void Update() { themodel.setParamFloat("PARAM_CHEEK", 1, 1); //this line simply has no effect themodel.update(); Debug.Log(themodel); } }

  • Ah I figured it out, I had to delete some scripts which controlling the model idle animation from LAppModel.cs, now I can modify the parameters outside of the class :smiley: Thank you so much, now finally I can sleep at night lol
  • Nice to hear you were able to solve the issue :D .
    Ran_TH said:

    ... I had to delete some scripts which controlling the model idle animation from LAppModel.cs...

    I'd have never thought of that... The next major version of the SDK will make such stuff much more transparent.
  • Yeah, hopefully! With no clear documentation most of us could only rely on sample scripts provided..with no clear comments either which functions goes where, lol.
  • Yeah, that pretty much sums it up... I'm really sorry for that. But I think you can look forward to the next SDK on that part :# .
Sign In or Register to comment.