-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting up and using ChatdollKit from code without the prefab #285
Comments
Hi @ahmetardal , You can spawn the character all in runtime by following steps:
using UnityEngine;
using ChatdollKit.Model;
namespace yourapp
{
public class CharacterManager : MonoBehaviour
{
[SerializeField]
private GameObject chatdollKitPrefab;
[SerializeField]
private GameObject characterPrefab;
[SerializeField]
private RuntimeAnimatorController animatorController;
// NOTE: Multiple instances are not considered in this example
private GameObject characterObject;
private GameObject cdkObject;
public void SpawnCharacter()
{
// NOTE:
// - characterPrefab and chatdollKitPrefab should be INACTIVE when instantiate
// - Components in chatdollKitPrefab should be configured
// Instantiate character and set animator
characterObject = Instantiate(characterPrefab);
var animator = characterObject.GetComponent<Animator>();
animator.runtimeAnimatorController = animatorController;
// Instantiate ChatdollKit
cdkObject = Instantiate(chatdollKitPrefab);
// Set character to ModelController
var modelController = cdkObject.GetComponent<ModelController>();
modelController.AvatarModel = characterObject;
// Blink
cdkObject.GetComponent<IBlink>().Setup(characterObject);
// Face expression
cdkObject.GetComponent<IFaceExpressionProxy>().Setup(characterObject);
// LipSync
cdkObject.GetComponent<ILipSyncHelper>().ConfigureViseme(characterObject);
// Start ChatdollKit
cdkObject.SetActive(true);
// Wait for a brief moment after ChatdollKit activation to show the character after the idle animation has started
Invoke(nameof(ShowCharacter), 0.1f);
}
private void ShowCharacter()
{
characterObject.SetActive(true);
}
public void DestroyCharacter()
{
characterObject.SetActive(false);
cdkObject.SetActive(false);
Destroy(cdkObject);
Destroy(characterObject);
}
}
}
I'm happy if you give me the feedback to this🥰 I will add a demo to our project. |
Hi @uezo Thank you for the quick and detailed reply. I appreciate it. 🙏🏻 We'll try the example you've sent and get back to you as soon as possible. |
Hi.
Thanks for this great framework. It's a lot of work. uezo
We have successfully tested ChatdollKit in the Unity Editor but we're having problems while integrating it to our existing Unity app. In our use case we want to spawn ChatdollKit at runtime when we need it and we want to set and change the models at runtime also. Is there any sample code for this use case? For setting up ChatdollKit via C# code and not with a prefab in the editor?
Thanks.
The text was updated successfully, but these errors were encountered: