Hi, I’m trying to get my weapon to play a random appropriate animation using this function, but some anim sets only have for example 3 different attack animations, some have 4, some have 5, etc… so I’m trying to add them all to an array, then pick a random one of those animations to output, but since the array always returns the same number of entries I had to do an ‘Is Valid’ check before returning the animation, just in case there was no animation linked to the random number chosen, and if it’s not valid then it will go back and get another random number, but instead it always return valid so if it chooses a number without an animation linked to it then my character just T-poses. Does anyone know what’s going wrong and how to fix it? Thanks
Hey @Mikester4411 Good to see you’re still plugging away.
Ok so first off your “Is Valid” loop (is not valid -> exec) is only ever going to check the same random. You’re not choosing a new random with this approach. If it did work that way you effectively set yourself up for an infinite loop. e.g. if all in the array were invalid.
What you want to do is pass the Make Array return to a function that does the checks, but also will prevent an infinite loop. The return of your base parent function (get appropriate anims) should also return a boolean as to whether or not there is an anim to work with.
Choosing the random itself you first need to loop through the make array result and validate the elements. Create a new array with the valid anims (local var). From there use simple logic checks (not empty, greater than etc) to determine the return.
The end result is IF (Has Object) == true, then there’s a valid anim. Otherwise no dice, but your not stuck in an infinite loop.
Edit : Replace Random integer in Range with Random Integer … I sprinted through the build. my bad.
I’m curious about your opening statement “but some anim sets only have for example 3 different attack animations, some have 4, some have 5, etc”.
Personally I’d have a struct in each weapon that holds the anims. Pass a reference to this parent function and pull them directly.
It just seems you have say like 10 weapons and you’ve piled all of their anims into a single struct versus having the anims set in the weapon.