Animating an object from external simulation data (i.e. scientific visualization)

Is it possible to animate an object (for example, a cube) based on external simulation data?

I have a state-history (time, x-pos, y-pos, z-pos, x-rot, y-rot, z-rot) of an object that was computed from an external source (MATLAB, in this case). I want to animate this object based on this state-history.

Is this possible in UE4? And if so, how?

You could do this in 3 ways that I know of:

  1. If the animation is object-specific, bake the animation data on the object using animation software. Should give you great performance with the added features of Persona. Might take longer to do.
  2. If you’ve got this stored in a CSV file, you can import it into a ‘Data Table’](Data Driven Gameplay Elements | Unreal Engine Documentation). It should be fairly straightforward to read from it and drive the object transform (Highly recommended)
  3. If converting to CSV is not an option, you can read from your file in C++ and drive the transform from there. Wouldn’t recommend it, since asset management will become slightly painful.

You could do this in 3 ways that I know of:

  1. If the animation is object-specific, bake the animation data on the object using animation software. Should give you great performance with the added features of Persona. Might take longer to do.
  2. If you’ve got this stored in a CSV file, you can import it into a ‘Data Table’](Data Driven Gameplay Elements in Unreal Engine | Unreal Engine 5.1 Documentation). It should be fairly straightforward to read from it and drive the object transform (Highly recommended)
  3. If converting to CSV is not an option, you can read from your file in C++ and drive the transform from there. Wouldn’t recommend it, since asset management will become slightly painful.
    [/QUOTE]

So I was able to get this “working” a while ago for a project by using method 2 as you described. Now that I have newfound free time, I’m trying to clean up and generalize the implementation.

I accomplished the animation by using the ForLoopPerTick macro (found elsewhere on these forums), and on each tick I’m updating the world transform of the object based on the Data Table I created from the CSV file. This gives me some really smooth and clean animation after some small tuning. However, I can’t easily control the length of the animation. I know how long it should be from the state-history data, but I don’t know how to enforce that length.


I’m now experimenting using a Timeline and using the state-history data as “Curve Assets” on the timeline (i.e. these represent the actual x and y positions of my object over time from an external simulation). This way, the animation runs for the exact time I need it to. However, now the animations are super jerky and choppy.


I’m not sure how to solve these issues. The Timeline implementation seems the most intuitive and results in accurate time but choppy animation. The update-world-transform-per-tick implementation is a bit of mess to set up and control animation length but results in super smooth animation.

Any ideas?

What frame rate is your external simulation data sampled at? If you fix your sample rate, you can consistently get accurate length. e.g if you sample at 30 fps, you can use Delta Time in Event Tick or Loops Per Tick to force that frame rate on every object. The higher the sampling rate, the smoother your animation will look. If the sampling rate varies, you need to store it in the data table for each animation.

I’m not sure if I follow completely. I know my sample rate is constant, but I cannot get new data (the sim was on a computer I know longer have access to). A small example of the data is below:

Time X-Pos Y-Pos
0 0 0
0.001 -1.4974e-06 3.8921e-06
0.002 1.7803e-06 1.5135e-05
0.003 4.137e-06 2.846e-05
0.004 4.4771e-06 4.3538e-05
0.005 9.3074e-07 6.0197e-05

Thus, my time-step from my raw data is 0.001.

How would I make a steady frame-rate?

EDIT: Looks like the formatting of that table didn’t come out right…

So is that 0.001 seconds? Or is it just a sequence number? If it’s 1 millisecond, then that is too fast to be processed within a typical 16 ms frame (for 60fps). You can just read every 16th row from your table every Tick and that should take care of the length. Since your target frame rate can vary, you can detect the frame time (Delta Time) from Event Tick and read the corresponding row from your table.
If on the other hand, 0.001 is just a sequence number, you need to figure out how long the animation actually runs and then do some math depending on Delta Time to read the correct row every tick (or every few ticks).

Hi,

I have similar problem for my project as you mentioned years ago on this post!

I am using the *“Runtime DataTable” plugin and i have managed to import my actors in the correct position. I use the “ForEachLoopperTick” macro as you mentioned and my actor make the animation but not in the correct time. Meaning that i have not managed to match the Game time (Tick) and the time (from the corresponding column) of my csv (the csv has been raised from a traffic simulation ).

So can i managed to match the csv simulation time with the unreal game time? Have you managed it?

(the “UpdateArrayfromCSVfile” node is from the Runtime Data table plugin I mentioned above)

Thanks for your answer.
But if my application is real time situation, How can I do or which option you recommend?