1
\$\begingroup\$

I am making a prototype for a Mario game and am having difficulty completing a canned animation for a prefab. There is an item box asset that has 3 materials and an "ItemGet" animation. One of these materials has an active emission property that is supposed to turn off during a specific frame of the "ItemGet" animation. These boxes will have an "Active" and "Inactive" state.

enter image description here

  • While "Active", the item box just bobs up and down and IF Mario hits the trigger, the "ItemGet" animation plays (and the player gets a unique item). The box then becomes "Inactive".
  • While "Inactive", no animations play, the emission effect is gone and the trigger cannot be reactivated.

Challenges:

  • finding the correct property to set a keyframe for in the Animations panel.
  • Making sure Active versions of the prefab remain Active after any ItemBox becomes Inactive and that all materials don't change when GetItem plays.

Ideas:

  • Instead of keying the emission on/off property (assuming that exists and does what I think it does; trouble finding it), swap the materials.
  • ( . . . ), swap the mesh.

Can somebody please help me find a viable way to finish this animation that fits this object's intended use-case?

\$\endgroup\$
3
  • \$\begingroup\$ For the standard shader, the emission property is easy to find inside the animation: GameObject -> MeshRenderer -> Material -> _EmissionColor. If your material is authored differently though the path may differ. \$\endgroup\$ – DMGregory Jun 25 '19 at 3:18
  • \$\begingroup\$ Changing that changed the color for the entire object for some reason, all 3 materials changed \$\endgroup\$ – hatinacat2000 Jun 25 '19 at 9:27
  • \$\begingroup\$ To change just one material, you can use the MaterialReference[i] property, where i is the index of the material you want to change within the renderer's array. \$\endgroup\$ – DMGregory Jun 25 '19 at 10:57
1
\$\begingroup\$

If it were me, working on Unity or not, I would have two classes/prefabs and swap. The idea is that the active object will be replaced with a different object that is inactive. Simple.

To do that, in the event that handles the interaction with the object, you can instantiate a new object of the inactive kind, copy the transform properties (parent, location, rotation, scale) and destroy the old object.

You would not have to worry about the animation frame which the object is. You would not have to worry about modifying the object, or affecting other objects of the same kind. And you would not have to worry about changing materals, et. al.


I have no idea on turning off emissions, et. al. I have only a passing knowledge of Unity.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.