UnityEditor in a build
Hello! I've been working in a platform that allows people to create games using images and texts. One of the main features is to create animations in runtime using sprites. So, I made a script that creates the controller and the animations. It works perfectly in the Unity editor, but when I did the build, it failed. The error says "error CS0234: The type or namespace name 'Animations' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)". I undestand that the library UnityEditor doesn't work outsite the editor and that's why the build is failing. But, is there a way to solve this error without changing the whole script? And how?
This part is related to the animator. I was thinking that using the library UnityEngine could work. But I don't know if this one can help me to create the animator and its parameters and states. Here is part of the code.
UnityEditor.Animations.AnimatorController controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Resources/StateMachineTransitions.controller");
controller.AddParameter("quedaQuieto", AnimatorControllerParameterType.Trigger);
var rootStateMachine = controller.layers[0].stateMachine;
And the creation of the animations uses classes like EditorCurveBinding
, ObjectReferenceKeyframe
and AnimationClipSettings
which depend of the editor. I don't know if the UnityEngine library could work here.
I appreaciate any given solution to this problem. Thank you.
Answer by liudgervr · Sep 22, 2021 at 08:40 AM
You should try to put your editor only code in if statement?
#if UNITY_EDITOR
UnityEditor.Animations.AnimatorController controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Resources/StateMachineTransitions.controller");
controller.AddParameter("quedaQuieto", AnimatorControllerParameterType.Trigger);
var rootStateMachine = controller.layers[0].stateMachine;
#endif
Your answer
Follow this Question
Related Questions
Why does this keep happening? 0 Answers
Disable automatic anim "Loop Time" check box 1 Answer
Animation not working when I build 0 Answers
I can't see or access a state in the Animation Controler 1 Answer