Answered

Problem with object reference in animation events

Kacper 2 years ago updated by Peter - Soxware Developer 2 years ago 3

Hi, I have events on animations that have objects connected to them. Is there any way to connect object to animation event in umotion? Because now, everytime i edit my animations, unity looses object reference, and it is really troublesome.

UMotion Version:
1.26p05
Unity Version:
2022.1.6f1

Answer

Answer
Answered

Hi,
thank you very much for your support request.

Unfortunately, animation event parameters that reference objects are currently not supported in UMotion. I've added this to my to-do list but can't promise when it will come.


I'm really sorry for the inconvenience. In the meantime, is there any chance you can workaround that limitation somehow?

Best regards,
Peter

Answer
Answered

Hi,
thank you very much for your support request.

Unfortunately, animation event parameters that reference objects are currently not supported in UMotion. I've added this to my to-do list but can't promise when it will come.


I'm really sorry for the inconvenience. In the meantime, is there any chance you can workaround that limitation somehow?

Best regards,
Peter

Hi Peter, 

Thank you for your quick response. I'm really glad that you have this in your plans, cause Umotion is a hell of a tool, and I love it! 

As for the workaround, our programmers could think something out, and fix it if you would show them the class where to do it;)

Best regards,

Kacper

Hi Kacper,

thanks for the kind words. I'm glad to hear that you enjoy working with UMotion.


As for the workaround, our programmers could think something out, and fix it if you would show them the class where to do it;)

There are several things you could do as a workaround:

  1. Avoid using object references by replacing them with strings/names or by having the references stored in a MonoBehaviour (Inspector fields) and referencing them via indices in your events.
  2. Write a custom UMotion export script that preserves the object references already stored in the animation events:
using UnityEngine;
using UnityEditor;
using UMotionEditor.API;

[InitializeOnLoad]
public class UMotionExtensions
{
   static UMotionExtensions()
   {
      ClipEditor.AddMenuItem(ClipEditor.MenuCategory.File, "Custom Export", MyMenuItemPressed);
   }
   
   private static void MyMenuItemPressed()
   {
      // Reference the *.anim file your export is going to overwrite e.g. by searching for a file with the same name as the current UMotion clip (use ClipEditor.GetSelectedClipName();)
      // Use AnimationUtility.GetAnimationEvents() to get current anim event data of *.anim file
      ClipEditor.ExportCurrentClip(); // Now UMotion exports the clip and overrides the *.anim file
      // Use AnimationUtility.SetAnimationEvents() to replace the anim event data with the original anim event data
   }
}


Unity Documentation: https://docs.unity3d.com/ScriptReference/AnimationUtility.SetAnimationEvents.html
UMotion API Documentation: https://www.soxware.com/umotion-manual/UMotionAPI.html

Please let me know in case you have any follow-up questions.

Best regards,
Peter