Alex ๐Ÿฆ… Profile picture
May 1, 2023 โ€ข 8 tweets โ€ข 4 min read โ€ข Read on X
Is your game struggling with performance?

Here is how to run your Unreal C++ code asynchronously to avoid bottlenecks.

A thread ๐Ÿงต๐Ÿ‘‡๐Ÿผ Image
A little bit of context:

I am working on integrating @Tolgee_i18n localization tools inside Unreal Engine.

One of problem I've encountered is the performance hit coming from refreshing the Localization Manager resources.

A single call would take 450ms and drop the FPS to 2. Image
1. Investigating & diagnosing the issue

The first step we need to take is to add as many TRACE_CPUPROFILER_EVENT_SCOPE in performance-heavy code. This will measure the impact of the function's execution.

As a general rule of thumb, when in doubt, always add more. Image
2. Evaluating if the code can run async

Certain functions can only be executed on the main thread (e.g.: Creating UObjects).

In most cases, Unreal's code marks these portions with: check(IsInGameThread()).

This is a clear sign the function should NOT be ran async. Image
3. Converting to async

All we have to do is to wrap our code in a lambda and call AsyncTask.

The first parameter is the thread type. We will go with AnyHiPriThreadHiPriTask because we want our work to get prioritized.

The second parameter is the lambda with our code inside. Image
4. Re-evaluating performance

When running our latest changes we can see the calls to our functions get spread across multiple threads depending on the workload and priority. Image
5. Checking result

The execution still takes 450ms, but it's no longer blocking our main thread so the player can enjoy a smooth experience.

All the FPS spikes are gone by writing just 3 lines of code. Image
That's all for today!

If you learned something new:

1. Follow me @OutoftheboxP for more of these
2. Retweet the tweet below to share it with your fellow developer friends.

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Alex ๐Ÿฆ…

Alex ๐Ÿฆ… Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @OutoftheboxP

Feb 20, 2024
Over the years, I've worked on a wide range of projects from small indie ideas to AAA games.

Here is how I would build an interaction system from scratch in Unreal Engine if I were to start a new project today.

A thread ๐Ÿงต๐Ÿ‘‡๐Ÿผ
1/17 General Philosophy

The main goal is to make an architecture that's easy to maintain. To achieve this we are going to go for simple bare bones solutions.

We are not going to develop a one-size-fits-all solution, instead, we aim to keep complexity to a minimum. Image
2/17 Limiting inheritance

Let's take the example of a door.

If we have an Interactable base class, the next logical step is to create a Door class inheriting from it and add the rotation logic.

This way the user can open the door by interacting with it.Image
Read 20 tweets
Jan 8, 2024
Here is how to create your own editor mode inside Unreal Engine.

Extend the editor with custom tools like the Landscape mode tailor to your own project.

A thread ๐Ÿงต๐Ÿ‘‡๐Ÿผ Image
1/4 Create the EdMode subclass

The EdMode subclass is responsible for registering and initializing the mode. It provides access to crucial virtual functions such as UEdMode::Enter & UEdMode::Exit which are triggered selecting and leaving the edit mode. Image
2/4 Create the ModeToolkit subclass

The Toolkit is responsible for creating the UI panel. It allows you to fully customize the panel with custom widgets are leverage the built-in DetailsView panels. Image
Read 6 tweets
Jan 7, 2024
Here is how you can run custom logic during the engine initialization from your own modules.

A thread ๐Ÿงต๐Ÿ‘‡๐Ÿผ Image
Registering callbacks is usually straight forward:

You get a reference to an object, access the delegate and add your callback.

However things can get tricky when it comes to engine initialization.
The main problem is you risk registering your custom logic too late - after the delegate has been fired.

To avoid this kind of problems, Unreal has FDelayedAutoRegisterHelper which gives access to a bunch of critical delegates and automatically registers the callback.
Read 8 tweets
Mar 4, 2023
How to write and refactor code without introducing any bugs.

Write your first Unreal Engine test today in 6 steps using Rider.

A thread ๐Ÿงต๐Ÿ‘‡๐Ÿผ
First off, let's discuss what automation tests are and what their purpose is:

Automated Tests are a controlled environment where you can verify the outcome of a piece of code against the expected result. They ensure our code behaves as expected while developing/refactoring it.
Step 1: Create the test class

1. Navigate to the module you want to add the test file to inside Rider.
2. Right-click the module project
3. Go to Add โ†’ Unreal Test Class Image
Read 11 tweets
Jan 14, 2023
Do you need to optimize your game?

Here is how to use Unreal Insights. A tool that will help you analyze the perforce of your game.

A thread ๐Ÿงต๐Ÿ‘‡๐Ÿผ
Step 1: Simply add the TRACE_CPUPROFILER_EVENT_SCOPE macro at the start of all of the functions you want to analyze.

Inside the parentheses, you can add any text you like, but I recommend using the ClassName::FunctionName for visibility.
Step 2: Start UnrealInsights.exe

This can be found inside *Unreal Directory*/Engine/Binaries/Win64
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(