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:
Create Animation in project view
Drag it onto Cube in scene view
Animate Cube
Create Prefab of Cube (with Animation) in project view
Create Empty in scene view, place it at same location as Cube
Make the Empty the child of the Cube, breaking the Prefab
Drag the Cube (with Empty child) onto Prefab
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!
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…
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…).
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.)