Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

If you have any questions, reports, suggestions, or requests about Live2D, please send them to this forum.
※We cannot guarantee statements or answers from Live2D staff. Thank you for your understanding in advance.
 
Live2D Cubism
Cubism Products and Downloads
Cubism product manuals and tutorials
Cubism Editor Manual    Cubism Editor Tutorial    Cubism SDK Manual    Cubism SDK Tutorial
[INFORMATION](03/28/2024)
Cubism Editor 5.1 alpha version is now available!
Find out how to use the new features here.
Please take this opportunity to use it and give us your feedback!

For more information and download, please check out the Cubism Editor 5.1 alpha category.

How do I reference the model from a script?

edited December 2023 in Help
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!
  • 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.