Average an Array of Float Values

I’m using an eye tracker to try and calculate an average for pupil dilation which is a proxy for the workload.

Pupil dilation in this case comes in as a float and I’ve created an array for each of those dilation values per tick.

In essence, I’m hoping to get a workload average over time so I can set that as a baseline on the fly but I can’t seem to get the array of floats to average correctly as they always increase and never level out. Probably something wrong with how I’m thinking about the math here but, I could use the help.

Here are the blueprints I’m using so far for the project.

Macro to sum array: Sum-of-array-attempt — ImgBB

Sum of array and divide by the number of entries to calculate average/mean: Average-Dilation-Attempt — ImgBB

Appending of pupil dilation each tick to the array: Screenshot-2021-01-20-141926 — ImgBB

Setting of pupil dilation variable: Screenshot-2021-01-20-141912 — ImgBB

Here is the whole picture! Thanks @ClockworkOcean

Can you show the whole thing, it’s hard to tell from these snipped pictures.

I’m suspecting your problem is using tick to append to the array, because that’s going to happen every frame regardless of whether you have new variables to add.

I notice you’re adding LeftEyeDiameterMm to the array even when it’s zero. Is that what you want?

BTW, you can say:


There is also:

or roll your own function:

If you make it pure, you can call it like this:


Ah! excellent point, I do not want to do that. I’ve now added a boolean where if dilation is > 0 then it adds to the array.

I couldn’t seem to get the add the same way you had it and did add unique instead. Maybe that is due to my version being on UE4.23 but it seems to have the same pins and hopefully works the same way.

Now that segment looks like this:

Thanks a ton!!

I think you should have it. Pull a pin from the array and search for ‘add’:

I put some more stuff in the previous comment you might find useful also.

Point is: does it work!?

PS: Don’t think you want ADDUNIQUE, as it will screw up your average…

If you made SumOfLeftEyeDilation a local variable to the function, you should be ok. But if you didn’t you need to set it to 0 every time here:


First of all, sorry for the delay here, I was unable to access our lab for a while.

I’ve since attempted the solution you proposed but still seem to be getting consistently larger values only and the average only goes up.

Here are my current blueprints:

The Dilation Average Function looks like this:

I’m not sure the issue here but it might be the lack of division working how we want or maybe the length isn’t getting calculated correctly?? Regardless, this is what I get with the current setup:

Again, very grateful for your help on this and appreciate the guidance.

Thanks to @ClockworkOcean I was able to get this work swimmingly.

For posterity, here is the functional blueprint in full as well as some supplemental images.

Full Blueprint

Blueprint Components


Average Calculation Function

I’m now going to try and work with this average to establish a baseline at 5 min or so of game play time and then make a GUI for workload in-game.

Fab! :slight_smile:

I actually just released a plugin that implements this feature! It’s called Fortuna Extended Function Library and contains functions for adding arrays, converting arrays, and getting the average from arrays (Plus a lot more)