Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Please limit one question/topic per post.
Please provide the following details depending on types of question

▼ For question regarding Editor, please provide:
- Live2D Software Version: (e.g. Cubism Editor 3.1.02, Euclid Editor 1.2.02)
- OS & Version: (e.g. Windows 10, macOS HighSierra)
- PC Model: (e.g. MacBookPro 2017)
- Graphics Specifications: (e.g. GeForce GTX 950M)
- Memory: (e.g. 8GB)
- Illustration Software used: (e.g. Photoshop, ClipStudio, SAI)
- Attach screenshot or capture video to show your problem:
---------------------------
▼ For question regarding SDK, please provide:
- For us to reproduce the issue you wish to inquire about, please provide either a minimum project file which has the issue. or specific instructions on how to reproduce the issue.
- Types and version of Cubism SDK you are using.
---------------------------
▼ For question regarding Cubism Software License,
For issues related to purchasing, your order, license key, and subscription, please contact us via contact form:
https://www.live2d.com/en/contact/contact_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();
            }
    
    
            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(); } 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.