Issue regarding Array in my game.

Dear community,

I am an intern at a game company, and I’ve been working with the Unreal Editor for two and a half months now and I have created a mechanic for a game that has this function:

  • Saves the player location per frame. (Per EventTick)
  • Whenever I press the key bound to the function, “reverses back time”, meaning, it reads the previous locations of the character stored in an Array, and blends a transform between said array index.
  • I can only reverse back time if i have enough of a pickup (there’s a pickup that gives me energy to use this function, whenever it hits 0, I cannot use this function anymore.)

I have however hit a wall with the following problem:

  • Once it starts saving the positions, my frame drops (at least 30fps) and keeps dropping as length of playtime keeps ticking away.

What have I tried to do to fix my problem?

  • Put a float variable to a branch (A>0) and on false will not keep on saving locations)

  • Set a limit to my Array using the Array Resize function.(Only works whenever the total Length of the Array hits 200 (I have done this because, when I have a full progressbar in my hud with the energy to reverse the time, it’s enough to reverse 200 frames)

  • Tried to bind an Array clear on EventBeginPlay

  • Measure various information (ArrayLength, FrameCounters, Succesful clears, etc.) none of this information made me wiser, or able to fix it.

PROFILER INFORMATION

  • Checked the Session Profiler for other things that could possibly cause a problem with the performance.

I would gladly accept any knowledge, workaround, or feedback on this piece of code in my blueprint, and I’ll be happy to share more information if needed.

Best regards,

Py.

Woah… yeah, nah… don’t write/load saves every tick.
That is a Bad Thing ™.
Besides, there is no need to do that if all you want to do is read from an array on an object/actor currently in game.

Just make the array a variable of the item that stops filling up once it reaches a certain limit or time.

Only save it if the player chooses to save the current game.

I have already done this, you can see that I have put an ArrayResize at the end of that piece of code, but I think it doesn’t work, if I limit the information stored to 200, it should be okay, performance wise, but it’s just getting worse and worse over time. And I really want this mechanic inside of the game, it’s really cool.

So do you have any other advice other than don’t do this?

Best Regards,

Py.

So… You have already corrected the fact that you’re performing massive amounts of storage I/O? The array comment was one of two in the response, and you’ve only replied to the one.

You’re writing and reading from disk hundreds of times every few seconds, which is insanely slow, and it’s probably getting worse over time because the disk I/O requests are continuing to pile up.

What Kris means is that there’s no need to save your frame array to disk - just keep it in an array in memory. That should be several gazillion times faster (rough estimate). As long as the array has a max size, you shouldn’t run into memory issues. (If you fail to limit the array size, you’ll quickly run out of RAM and probably freeze up your system or something.)

^ this.

Hence “That is a Bad Thing ™” :slight_smile:

Okay, that’s fair, but how do I make the game save everything to memory, rather than write it to the disk?

Best Regards,

Py.

Just create an array variable on your BP and use it instead of the “Poppetje” from your save game object.

Also, you don’t need to “Set” it after using an Add/Insert/Resize etc. Those nodes act on the array reference, not a copy. (Otherwise, they would return the copy as an output.)

Moving it to memory will indeed make it a several gazillion times faster. Moving it to C++ would be the next step to make it even faster. Then storing only the delta location and rotation like done in networked games.

Thanks for the input, I will try to give this problem another shot when I have time, and will update this post with a result.

Best Regards,

Py.

So after a lot of testing I managed to fix the game’s slowing problem by indeed replacing the save game variable with a transform Array, the only problem that I have right now is that my Array’s length is 200, I set this value because my character will never have more energy to use for over 200 saved frames. So once the Array hits 200 frames, new infomation will not be stored anymore, meaning that if I would ever want to use this mechanic at over 200 saved frames, it will always send me back to where the last frame has been saved. I have added an image to make this problem visually understandable, if anyone knows a fix, or a way to make my Array save new information at index 0 instead of 200, I’d love to know so.


Player starts at the left side of the screen, picks up the orange ball and the Array starts saving until the red line begins, if I use the mechanic then the blue line represents where it has last saved a frame and I get sent back to that position.

Best Regards,

Py.

I have fixed the problem, my solution is to add a remove index function and set the index at 0, meaning it will delete the oldest information and keeps adding new.

Thank you all so much for the help, I really appreciate it!

Best Regards,

Py.

I will close this thread!

You can also use Insert Item to insert at index 0, then trim the array to a length of 200 if necessary.

​https://docs.unrealengine.com/en-us/Engine/Blueprints/UserGuide/Arrays/ArrayNodes​​​​​​