1
\$\begingroup\$

I am new to Unity and not game developer at all, so sorry if this question might be stupid. I have an animation in my project. Is there some points where Unity calculates/recalculates the next position of animated character? Is there some function like for example "OnAnimationSample()"? I want to make calculations between theese points. I didn't found anything in the documentation and hope that someone more experienced than me know some way to tackle, although the task is quite peculiar.

I am programming a simulation environment for robots. There is a need to take screenshots at certain events happening by means of raycasting (gathering img data for CNN). The robot has various physical specification like for example speed. I don't want the environment depends on speed of the robot, so I am planning to make calculations and screenshots constatly for example in between two animation "milestones". That will slow fps and overall game down, but I don't mind since I need only right data at right step. For example suppose there are exist such points in the Unity, when before taking any movement the Unity calculates the next state of the object being animated. I want to stuff my calculation and such, that next animation step won't start until all is done.

I hope that explained not so tricky. Say if the explanation is obscure I will try my best again.

\$\endgroup\$
2
  • \$\begingroup\$ This sounds like an XY Problem. Can you explain to us what you are actually trying to calculate and why? Perhaps there is a much better approach to it than yours. \$\endgroup\$
    – Philipp
    Jul 2 '20 at 7:42
  • \$\begingroup\$ Ok, I then edit this post in order to explain. Thanks \$\endgroup\$ Jul 2 '20 at 7:49
1
\$\begingroup\$

From what I have understood from your question you are trying to perform certain calculations based on animation state so here is few approaches:

  1. You could have a script inherited from StateMachineBehaviour instead of Monobehavoir and attach it to animation states. For further details check out unity's documentations https://docs.unity3d.com/ScriptReference/StateMachineBehaviour.html
  2. You could have animation events marked on animation frames and invoke those events as per your need. For further details check this out https://docs.unity3d.com/Manual/script-AnimationWindowEvent.html#:~:text=To%20add%20an%20Animation%20Event,mouse%20to%20reposition%20the%20Event.
\$\endgroup\$
2
  • \$\begingroup\$ Thank you for your hint. You understood right. \$\endgroup\$ Jul 2 '20 at 8:35
  • \$\begingroup\$ You're welcome. Glad to be useful :) \$\endgroup\$ Jul 2 '20 at 8:36
1
\$\begingroup\$

If you want to perform some calculation before the animation system and the physics engine operate on the object, then the right event for that is FixedUpdate.

For more information when Unity executes which event, check out this diagram about the order of execution in Unity.

\$\endgroup\$
1
  • \$\begingroup\$ Yep, I am staring this diagram two days :) \$\endgroup\$ Jul 2 '20 at 8:38

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.