Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by mbrako · Aug 04, 2016 at 11:03 PM · animationsslidercontrol3d model

How to control animation with slider

Hello, Im a noob to unity.

Ive searched and it seems there have been similar questions to this, but answered with advanced knowledge. I have no idea how to start this.

(attached image) I have a hand pinching a block. i want to use the slider in a way that when I slide the knob to the right, the animation will advance, pinching the block.

I have the animation exported in fbx format and placed in my canvas. I added the slider but don't know where to go from there as far as connecting it, and the correct scripting for it. alt text So anything that is along the lines of using the slider to control the imported animation would be great. Please help! Thank you!

screen-shot-2016-08-05-at-14612-pm.png (154.9 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KuR5 · Aug 06, 2016 at 06:27 AM 0
Share

$$anonymous$$ay be this link can help you.

avatar image mbrako KuR5 · Aug 09, 2016 at 09:22 PM 0
Share

Sorry, I just realized this reply was here. Still getting used to the forum. I will try it out and let you know if it worked

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by vfxjex · Aug 07, 2016 at 05:17 AM

Hello I think I answered this concern base on the link @KuR5 shared, but if things are not yet cleared let me try to clarify it.

First of all make sure that the attached component of your model is "Animation" not Animator.

second make sure that the animation of your hand is "Legacy". if you don't know how to make your animation Legacy just right click the inspector "Tab" of your animation clip and check the Legacy checkbox. make sure you switch back to normal after doing this so.

Third in the animation component, there is an Animations attribute. change the size to 1 and drag and drop the animation of your hand.

4th Copy and paste this Script and attached it to your model in the Hierarchy. Don't forget to drag and drop the slider into the slider variable.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class AnimControl : MonoBehaviour {
     Animation anim;
     //Drag and drop your Slider into this variable.
     public Slider slider;
 
     // Use this for initialization
     void Start () {
         anim = GetComponent<Animation> ();
     //Make sure you have attached your animation in the Animations attribute
         anim.Play ("myAnimation");
         anim ["myAnimation"].speed = 0;
     }
 
 
     // Attached this on Slider's On Value Change
     public void AnimateOnSliderValue () {
         anim["myAnimation"].normalizedTime = slider.value;
     }
 }

Hope this works.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mbrako · Aug 09, 2016 at 09:12 PM 0
Share

Something isn't working but it looks like it almost is.

  1. I bring my 'handAnim' fbx into the scene. The part where you say to right click for Legacy ( I think we are using different Unity versions) but I changed the Animation type to Legacy and did 'Apply', you say put back to normal but I dont see a normal option'. see screen shot below on 'answer' ( I couldnt add on reply)

  2. Confirmed Im using Animation with size 1, used your script and where it says 'myAnimation' replaced with with 'handAnimation', and dropped it on my handAnim component hierarchy, and after bringing my slider into the scene, and also dragged and dropped the slider into the Slider variable

  3. // Attached this on Slider's On Value Change public void AnimateOnSliderValue () { anim["myAnimation"].normalizedTime = slider.value; --For this part, On Value Change under Runtime, I connected the 'handSlider (slider) and selected 'value' (is that right?)

  4. I hit play, notice there are no errors in my console but the slider isn't affecting the animation. Now I do realize my animation starts and ends (23.0-49.0) Will this affect the slider when the slider triggers the animation and do I need to indicate that its starts at frame 23? If so, how?

Thanks A TON!!!

avatar image
2

Answer by Rodlaiz · Feb 22, 2017 at 02:56 PM

The solution provided by Vfxjex doesn't work for me because the Animation component has to be marked as Legacy. I try this solution using Animator instead of Animation and it works for me:

 using UnityEngine;
 using UnityEngine.UI;
 
 public class ControlAnimation : MonoBehaviour
 {
     private Animator anim;
     public Slider slider;   //Assign the UI slider of your scene in this slot 
 
     // Use this for initialization
     void Start()
     {
         anim = GetComponent<Animator>();
         anim.speed = 0; 
     }
 
     // Update is called once per frame
     void Update()
     {
         anim.Play("TEST_DELETE", -1, slider.normalizedValue);
     }
 }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ashishsfb · May 10, 2017 at 11:13 AM 1
Share

I am trying to control my animation via scroll wheel, and this method works fine. Thanks for posting. :)

avatar image Mamello ashishsfb · Oct 13, 2020 at 11:01 AM 0
Share

I'm trying to do the same thing. Please explain, with an example, how you did this. Did You use GetAxisRaw to check the scroll wheel's position?

avatar image
0

Answer by mbrako · Aug 10, 2016 at 07:27 PM

I got it working! Thanks @vfxjex

For anybody thats looking for how I got it to work, I put a step-by-step tutorial (Im still a noob to Unity so my explanation is very basic!!)

Lets use a simple example to demonstrate how to use a slider to control a simple animated object that has been exported (fbx)

Im using a model of fingers pinching a skin anatomical figure that I built and animated called 'handAnimationsv002'. I’ve exported the model, joints and blend shape (animated from frame 0-24). I will refer to the names I used in the project, but substitute whatever you may have. Use these images to reference the figures Figure 1-5 Figure 6-7 Import your fbx into your Unity project (Im using the 2D option)

Figure 1. Select your model. Go into the ‘Rig’ tab. Change Animation type to Legacy and hit Apply.

Figure 2 Create your Canvas (this will add an EventSystem to your project). Drag your fbx over the canvas to create a child of Canvas.

I adjusted the scale and rotation for this just because my export came out too small. Ive also put in a directional light (default) to light this model.

Expand the fbx icon in your project folder to reveal all the parts of the model.

Ive changed name of the icon with the play button to ‘animateHand’ for the script later.

Drag the ‘animateHand’ icon into the value of Animation and make sure your size is set to 1.

Hit Play. You may not see anything. In this case. Ive adjusted both my canvas and main camera settings. I also switched over to 3D view temporarily to see how things are aligned.

Figure 3 Take note of your Pos X and Pos Y to use on your Main Camera Settings. Change the render mode to ‘World Space’ .

Figure 4 Select the Main Camera and Plug in the X and Y position to match the canvas.

Using your 3D scene, move the camera in Z-Axis to get your models in view.

Adjust the Size and Clipping Planes accordingly.

Hit Play now and the scene should be in place. If you notice the object animates, turn off ‘Play Automatically’ on ‘handAnimationsv002’ setting

Figure 5 Create the script ‘AnimControl’ and copy paste this script (courtesy of @vfxjex )

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class AnimControl : MonoBehaviour { Animation anim;

 //Drag and drop your Slider into this variable.
 public Slider slider;

 // Use this for initialization
 void Start () {
     anim = GetComponent<Animation> ();

     //Make sure you have attached your animation in the Animations attribute
     anim.Play ("animateHand");
     anim ["animateHand"].speed = 0;

 }

 void Update (){
     anim ["animateHand"].normalizedTime = slider.value;

}

}

Select ‘handAnimationsv002’ in the hierarchy and drag the AnimControl script into the components area Then drag ‘Slider’ into the ‘slider value’

Figure 6 Select Slider in the hierarchy and drag Slider to the On Value Changed (Single) value

Figure 7 Select value for the Function

Press Play and try it!!


figure1-5.png (328.4 kB)
figure6-7.png (132.6 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jagjeet_65079871 · May 13, 2020 at 09:47 AM 0
Share

Followed same given steps..unfortunately it does not work for me.

I have fbx with animation and want to control the animation with UI slider.

I follow suggested steps with given script but animation jumps on the keyframes as slider moves...it does not show up in-between animation.

Any suggestion

Thanks

avatar image
0

Answer by sendmailtonani · Nov 03, 2021 at 04:20 AM

@Jagjeet_65079871

I think you must have ticked on whole numbers in the slider component.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

72 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity3D transition animation playing twice 0 Answers

Animation returns to the initial position 0 Answers

how to play two animations of one gameobject without reducing the weight or any speed 0 Answers

Corgi Melee Weapon script problem 0 Answers

Animation Running Game 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges