Trouble With Localized Keyframe Animations on Prefabs

Hi, Unity folks!
In searching for info on how to do localized keyframe animations on instantiated prefabs, I found these instructions by Targos:

I tried to follow the instructions, but don’t seem to be getting it right. Right now I’m just testing this out on a simple cube with an animation created in the project view and a prefab of that cube. I tried using a simple “OnMouseDown–Destroy–Instantiate” script, but the animation on the prefab always starts at the origin where it was recorded instead of the 0 position of the Empty that the cube is parented to. I also tried a version of the same script that references the Empty for transform.position and transform.rotation, but still got the same result.

I don’t have my project with me on this computer, so I may get the details wrong, but this is basically what I did:

  1. Create Animation in project view
  2. Drag it onto Cube in scene view
  3. Animate Cube
  4. Create Prefab of Cube (with Animation) in project view
  5. Create Empty in scene view, place it at same location as Cube
  6. Make the Empty the child of the Cube, breaking the Prefab
  7. Drag the Cube (with Empty child) onto Prefab
  8. Attach OnMouseDown/Destroy/Instantiate script(s)
    to Cube.

I also tried switching the parent/child around, making the Empty the parent, but it still didn’t work.

Does anyone know what I’m doing wrong? Thanks again for your help!

EDIT> Oh youve tried the empty as a parent-that should have worked, did you upload changes to prefab?

EDIT2> Can I see your code?cheers

Origional response>

Either Ive led you up the garden path…

or

After a quick skim over your steps, It seems like the empty is the child, right?

This may be the problem.
Unless Im reading wrong, the empty should be the Parent, and the cube with attatched animation should be the child…

Try that Ill check here later :slight_smile:
Peace
AC

Thanks, Targos! I’m not home right now, but I’ll send the code as soon as I get there. Yes, I tried using the Empty as the parent first, but it didn’t break the prefab, but it broke it the other way around, so I figured that’s what you meant by “parenting to.” I had never used an empty as a child before, but I thought maybe this was a special case. Sorry, I’m having trouble understanding my own language…

And yes, I uploaded the changes to the Prefab.

I’ll get back to you later. :slight_smile:

Terransage, maybe you could upload a project folder too? It sounds like a small project…
AC

Try this instead:

  1. Create Empty at 0, 0, 0
  2. Create Cube as child of Empty at 0, 0, 0
  3. Create Animation in project view
  4. Drag it onto Cube in scene view
  5. Animate Cube
  6. Create Prefab of Empty with animated Cube as child in project view
  7. Instantiate that prefab however and wherever you like, I think it should work.

Yoggy said:

Ahhh, thanks, Yoggy! That worked perfectly.

Thanks again, Targos! Until I read your post, I didn’t even know that localized keyframe animations were even possible. (I forgot that anything is possible in Unity.) Fortunately, I didn’t have to upload my project, which now stands at about 5 million MB’s (a slight exaggeration, perhaps…).

Pleased you got it sorted…
Cheers Yoggy
AC

This just saved me a lot of work in programs I don’t know yet (I’m under a tight Top DOG deadline, and while my programming is pretty much done, I still need to create my animations, amongst other things.)

Thanks a ton, guys!