Hello,
I have been using needle engine for creating a multiplayer game. Ive some issues syncing animator animations on my downloaded 3d model instance. Need help on how to get animator syncs!
I have tried PlayerState.IsLocalPlayer() but its not working for my downloaded model object.
Hi @narendra.chaudhary
can you describe what you’re doing right now and what your goal is? How do you currently sync animations and which models are you downloading from where? Have those models been exported with any of our integrations?
I am trying to download a readyplayerme avatar model (public url) and animate it using an existing controller. I am able to download and see the model but when animator and syncanimator is attached on it, it does not animate.
I have seen the sample animator code and doing the same, but what I have observed is the animator component is reparented but it does not lose the references of the original animator, the new model stays in T-pose but the old model is seen animating. (Img attached in attachment)
white model is static model that is in prefab that is spawned when user joins room
let go = this.currentObject; // downloaded model
let animator = this.mainanimator; // animator reference of a static model
// SyncAnimator is custom class for animation syncing across network
if (animator) {
animator.enabled = false;
const sync = GameObject.getComponent(animator.gameObject, SyncAnimator);
let parent = animator.gameObject.parent;
if (!parent) {
console.log("parent to animator is null, animator is" + animator.gameObject.name);
return;
}
go.name = animator.gameObject.name; // renaming the object name as we noticed that animations do not work if the object name was different,
// some error on nodes.<object name> is null
// move data over
var animatorInstance = GameObject.addComponent(go, animator) as Animator; // this statement just reparents the component to new object
if (animator) {
animator.awake();
animator.enabled = true;
console.log("new animator ", animator, animator.gameObject.parent);
} else {
console.warn("animatorInstance on downloaded model found null or undefined");
}
// adding Sync Animator Component to sync player animations on network...
let syncAnimatorInstance = GameObject.addComponent(go, sync!) as SyncAnimator;
if (syncAnimatorInstance) {
syncAnimatorInstance.currentSyncedTransform = this.currentSyncedTransform!;
} else {
console.warn("syncAnimatorInstance on downloaded model found null or undefined");
}
you have to call GameObject.removeComponent ideally before calling GameObject.addComponent. Otherwise the component will be on both of the objects
It would be better to not migrate it at all, but rather to create everything from scratch (GameObject.addNewComponent). Create a new Animator component, add it to the object, set the controller
If that doesn’t work, then try calling the initializeRuntimeAnimatorController
2. SyncAnimator
Currently it is limited that the SyncAnimator can’t change during runtime, so migrating it is not an option.
You can add it on the object when it is spawned, the object just needs to have an Animator attached