Inside of a Blend Tree when you add Parameters the only type that is in the inspector is float. How come Integers are not available?
I realize its a Blend Tree and makes sense to have floats but I was thinking if there was the ability to have integers then creating random animations would be a little bit easier. I could add the Int parameter in the inspector which would then let me add my animation clips (through motion fields) then write something like:
and tried taking care of it randomly but I get random values which starts the animation at the wrong point in the animation. If that makes any sense? Does anyone have another way to create random animations with animator?
in 4.x you can emulate this by creating a sub statemachine, with a first state that act like a selector; put a small clip(a few frame only) in this state that blend corrrectly to all your other random state, for each transition make sure that you donāt have an exit time, you want to change as fast as possible from this selector state to your random state.
void Start () {
anim = GetComponent<Animator>();
int pickAnumber = Random.Range(1,3);//exclusive never prints the last only goes 1 to 2
Debug.Log (pickAnumber);
//randJumpInt is the parameter in animator
//pickAnumber random number from 1 to 2 from above
anim.SetInteger ("randJumpInt", pickAnumber);
}
Mecanim.Dev, is there any chance you could expound on this process for Unity 4.x users? I cannot get any of this to work for me. My problem is the same as OPās, I just need mecanim to play random animations, one after another. How do I go about setting up from scratch with the sub-state machine, and are there parameters and scripts to needed to drive them?
Also, when I select the transition I made in the sub-state machine, my inspector does not look like yours, and with part of the graph cut off, Iām not sure what the whole system is supposed to look like. Any advice?
The cut off part was only showing one state walk, and all idle state were transitionning to this state.
Using the visual editor to setup the whole thing is one way to do it.
An simpler method would be to play your clip manually from the script with Animator.Play
Simply drop all your idle clip in your controller
and then from a script you choose which clip to play.
If you want tell me your unity version and I will build a small controller that will show you how to do it.
Iām trying to do a random animation in U5 but Iām getting confused. Iām not sure if itās buggy or my inexperience with it. I setup a substatemachine AttackRandom.
In there, there is an default transition that is empty. I also canāt change the default transition to say, attack1.
So I added a OnStateEnter to randomize the parameter and condition like this
Havenāt reach two years yet, the graphics and tools works great together, unlike unity where I have to āfightā to get third party integration working together.
The C++ portion has some quirks, which makes quite painful to get into, if you stick to blueprint, you are fine but limited in what you can do.
My main issue with Unreal is parts of the PhysX is wrapped in their own logic, which makes it harder for me to do certain setup properly. I integrate PhysX in custom engine before so I would have done so differently. Unitiy physx 4 also had a lot of issues but they resolve most of it in U5. Unity side is still not quite correct but it gives more control than UE4. Thatās a summary.
Guys. Iām not a great programmer-- Just an animator but I figured out how to do a decent random animation. Hereās how:
// This switches between 2 idle animations by using a 1D animation blender
// The idle animations have a trigger on the last frame called IdleEnded that triggers the randomizer
// One animation happens more frequently than the other based on the idleRange in this case
private void IdleEnded ()
{
int idleRange = Random.Range(0, 3);
if (idleRange == 0)
{
m_animator.SetFloat(āIdleRandomā, 1.0f);
}
else
{
m_animator.SetFloat(āIdleRandomā, 0.0f);
}
IdleRandom is the range from 0 to 1 (the slider parameter in the blend node) that blends the anims, and is always either 0 or 1 in this case. Its obvious how you could expand this beyond just 2 animations by making a .5 for the third etc. It solves the problem of substates having grayed-out input links and works on the very first time the animation plays if you were to set up IdleRandom in the start. Tested and works.
Not sure how this would handle animations of different lengths. Seriously we sure could use a node that did exactly this: Instead of blend-lists, a random play list with % odds per animation.