🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Oh My SHIP ! - Devlog Week 08

posted in Oh My SHIP! - DevLog for project Oh My SHIP!
Published July 16, 2022
Advertisement

This worst week of my development progress because no actual update is done. I start this week learn about how to create better programming for realtime applications in UE. After days of reading and learning I found some key points:

  • Avoid Event Tick as much as possible because this is expensive, especially from BP
  • Spawn and destroy is expensive to call and the garbage collector can make hitches if not done correctly
  • Creating object manager to update actor ticks simultaneously instead of individual actor ticking
  • If objects need ticking individually, deactivate their ticks on death
  • Try to implement physics for all the movements and remove them from ticks

Object Pooling

I've been searching about how much performance gains by using object pooling vs spawn destroy for large amounts of objects and keep getting mixed results on the internet. So I try to create simple object pooling using a blueprint. This test is using about 480 objects using linear velocity for the movements with event tick deactivated, and found it the object pooling is a bit faster. There is no stuttering happens from garbage collectors or from pooling operations during all the tests. Object pooling is get about 2ms and 14FPS faster during my test so this really helps to get some performance.

Physics movements

For the movement updates, I have an idea to decrease the movement input by using Event by Time every 0.1ms. And using physics angular velocity and linear velocity to smooth blending between movement inputs. Something on my mind is adding physics can make the game slower. but the physics is not full simulations, just take the linear and angular velocity. After I make some tests this is surely much cheaper than SetActorTransform every tick.

Not actual framerate, this gif is only 33fps. Just showing my test process.

I create a simple test to compare the object pooling and physics movements. The result is:

  • Pooling+Physics 82fps 11.9ms
  • Pooling+Physics+OverlapDisabled 90fps 10.6ms
  • NoPooling+Physics 79fps 12.7ms
  • Pooling+GameTick 57fps 16ms

This is not accurate results depend a lot on other factors, maybe will get a smaller difference in good hardware. After running the test many times, the result is still very similar so it is something that needs to consider.

Failed Implementations

So for the movement updates, my idea is to try to decrease the movement input by using Event by Time every 0.1ms. And using physics angular velocity and linear velocity to smooth blending between movement inputs. This work good on simple object movements, but for complex movement inputs, it is so hard to do this and lots of hack to make the object move as intended. Sometimes it is much better just to change Event Tick to Event by Time and set how many updates we want every second. Slow objects can have fewer updates every second than fast objects. Makes me sure if physics based movements are worth it (not really).

As for Object Pooling, I'm still scratching my head on how to implement it. Basically, it is easy if all I need is just Spawn Actors as much as needed onscreen during game start and deactivated. And activate or deactivate during gameplay and put the object in specific positions and let the object do whatever they want. However, when I need to micro manage these objects in realtime using ObjectManager, things get out of palace.

First problem is when taking an Actor from the ObjectPooling, Because Unreal parallel event execution system, sometimes the actor is already taken but the ObjectPooling still not processing, and other request is coming will take the same Actor twice. This can be solved by creating a Request list and letting ObjectPooling execute all the requests one by one instead of direct requests. But by doing this, the ObjectManager can't get a reference to the specific requested actor so no way to set the start variables of these Actors.

Another workaround I can think of is the object manager requests including variables needed to pass to the actor. And the ObjectPooling will provide these variables to the Actor via the Bluprint interface. This can be work, but every Actor should have exact same Initial variable setups. This means I need to recreate all of the Enemy and Bullet Blueprints to these very specific needs and the amount of variables that need to decide in front. And guess what? It didn't just work as intended...

Some actors are not activated correctly. not only happens during the collision but also happens after Initializations. I tried a lot of iterations and keep getting the same results

The last thing I try to implement before posting this blog is adding a cooldown to every actor before can be spawned again, and this also does not work. My guess is on my way to activating or deactivating the actors, currently, I disable visibility, disable physics, disable generate hit events and/or generate overlap events, also disable my movement update using bool. Still, don't know how to disable Actor properly in Unreal. I wish there exist a boolean to disable or enable Actor like in Unity.... Any help would be appreciated.

To avoid myself keep stuck on this, I need to take a break from programming and start to create the 3D assets, sketching and cooking game design documents more, so I have a better view of the game code I need to create. Or just keep stubborn working on this till I make it. Will see in the update next week, thank you for reading.

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement