(apologies if this is in the wrong forum… it’s half coding and half Animation Editor… I had to pick one)
I’ve been using the animation editor to animate a camera. At certain points in the camera’s movement, I want a certain object in my scene to be enabled or disabled. So, I created two simple Javascript functions:
//disable an object
function disableGameObject (object:GameObject) {
object.renderer.enabled = false;
}
//enable an object
function enableGameObject (object: GameObject) {
object.renderer.enabled = true;
}
Then, for every time I need disableGameObject() or enableGameObject(), I add that function as an event to the animation at the appropriate time, and then drag the object in my scene into the function.
It works great! The objects on the stage disappear and reappear when they’re supposed to… until I save the game and close Unity. When I open up Unity again, the animation events are remembered, but it doesn’t remember to what objects the animation events apply. It will simply say “disableGameObject (null)” instead, even though the objects are still on stage.
Does anyone know how to fix this?
EDIT: I found a workaround. It’s almost as good. All I do now is, instead of passing a GameObject reference, I pass a string that looks for a GameObject of the same name:
//disable an object
function disableGameObject (objectName: String) {
object = GameObject.Find(objectName);
object.renderer.enabled = false;
}
//enable an object
function enableGameObject (objectName: String) {
object = GameObject.Find(objectName);
object.renderer.enabled = true;
}
Incidentally, due to the fact that the workaround was a code solution, this should probably be moved to the scripting forum.