Moving animation data between child/parent (Hint: Don't scale parents)

@ben
Hi all,
Well, there were a couple of things that irked me a little during BowlMaster, which ended up causing issues in this lecture.
Firstly, the pinsetter GameObject is scaled to encompass the area required. If it’s a standalone object that’s fine, but if it will ever become a parent, than that’s a problem since child positions are also scaled accordingly. This is why, in this case, it isn’t possible to simply copy the animation from the parent to the child, since the child was parented under world when the animations were made.

To fix this (I scaled to collider to begin with so I didn’t need to do this but this should work):

  1. Un-parent the Swiper from the pinsetter in the hierarchy
  2. Copy the pinsetter scale from the transform to the BoxCollider (the collider scale will look massive!)
  3. Set the scale on the pinsetter transform back to 1. Notice how the collider looks ok again.
  4. Re-parent the swiper under the pinsetter
  5. Select the pinsetter and go to the “swipe” animation in the animation editor. The pinsetter should still have the swipe animation so when played it all kinda looks the same as before.
  6. Add the properties you need from the swiper child (I.e /Swiper/translate.position)
  7. Select the keyframes on the pinsetter and copy/paste them to the corresponding property below on the Swiper.
  8. Delete the properties from the pinsetter object. Play and be amazed how this might have taken longer that redoing the animation :).

I hope that helped (I hope it worked) :).

But while am at it… The second thing that bothered me a wee bit, was the actual bowling pin asset. It’s a bit sloppy. It has rotation and scale on the source mesh (and bad tessellation that prevents it from smoothing properly). For static meshes you want to keep translations/rotations at zero and scale at 1 so the code can assume that with all properties reset, it should have the intended rest rotation and scale. And in case you want to manipulate hierarchies you don’t want to deal with the inevitable scale issues.
As far as the pin is concerned, it’s “acceptable” as long as it is under a parent and we’re manipulating that parent but after simplifying the pin object a few lectures earlier to consist of only one node, its root translate gets some nasty rotations and scale from the get-go, which isn’t good. For instance, checking if it is standing should surely just be as easy as (pseudo)?:
If angle between “Vector3.up” and “transform.up” is within this “threshold” then the pin is standing up…

So, some best practices:

  1. If you’re creating assets in the editor, which might later become a parent, keep (transform) scale at 1.
  2. In your content creation package of choice, for static objects, reset transforms so that position and rotation is a 0 and scale is at 1. (Always create your models to scale)
  3. To get a clean, smooth mesh: Don’t have unnecessary tessellation which will mess up your smoothing (vertex normals). The only exception to this is if you’re baking/applying normalmaps from a hi-poly mesh and/or are using displacements.

Cheers,
-Jan Almqvist

3 Likes

Come to think about it (in regards to the above list of how to fix the animation issue), the result might be that the Swiper becomes offset from the pinsetter when the animation starts to play (since they don’t have the same pivot). So as a step 9, you might need to shift the Z curve (maybe the Y as well) to be where you intended it to be. In the animation editor, choose curves, select the position.z property, press “f” to frame it, drag select all key frames and drag up/down (hold shift after drag to keep keyframes from moving left/right). If you have the editor window open, you can see the Swiper moving.
Maybe I should have tested this beforehand instead of guessing. Sorry if I’m wasting anybody’s time ;).

1 Like

I have found a reasonably quick fix. As we should know by now, the position.transform is animated because for each keyframe there are values recorded in this animation. The transform is a component with properties.
What I did:
I added the transform.position property of the Swiper child object to the animation, and inserted keyframes at the same point.
Then I went to each of the keyframes for the PinSetter object, copied the Transform component, and Paste Component Values in the transform object of the swiper at that keyframe. Then remove the PinSetter transform property and the Swiper transform.scale property that has been added after pasting.

This whole procedure takes a whole three minutes, if you’re discouraged (as I was) at the thought of redoing the whole animation.

EZ PZ lemon squeezy :slight_smile:

EDIT: this is effectively almost the same solution as Jan’s. His approach (unparent, adjust scale, reparent, copy/paste keyframes and then adjust based on different pivot positions) is quicker.

Thanks for that Jan. I’m finding that some parts of the course lack some of this good info that is going to help me when I start developing something on my own. Your advice on creating and using assets is going into my Unity Dev notebook.

Privacy & Terms