Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to get the thread name in Unreal Engine

I know that using FPlatformTLS::GetCurrentThreadId(), you can get the current threadID in Unreal. But how to get the thread name? (I am running this in Debug build where the thread name exists). I know that the profiler code in Unreal maps every threadID with it's respective thread name. I want the same, so can anyone tell me how to obtain thread name from a threadID?

Product Version: UE 4.19
more ▼

asked Jul 16 '18 at 10:03 PM in C++ Programming

avatar image

18 2 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You can get the name of a thread as an FString by using the thread manager like so:

 uint32 ThreadId = FPlatformTLS::GetCurrentThreadId();
 FString ThreadName = FThreadManager::Get().GetThreadName(ThreadId);
more ▼

answered Jul 17 '18 at 02:24 PM

DarkwindRichard (suspended)
avatar image DarkNemesis Jul 18 '18 at 05:23 PM

This works! Although some of the threads such as the main thread and the crash report thread, they return an empty string. Any ideas why? And is there a way to get even those names (across all platforms?)

avatar image DarkwindRichard Jul 19 '18 at 02:40 PM

If you take a look at the implementation of "FThreadManager::GetThreadName," all it does is attempt to find the runnable thread in its owned thread list. If the thread name being returned is an empty string, then either the thread manager does not own that thread or the thread does not have a name registered to it (though most likely the former is true). As far as I know, there would be no way to retrieve that thread name across all platforms as threads are typically referenced by their ID anyway.

avatar image DarkNemesis Sep 07 '18 at 06:09 PM

This doesn't work for playstation. I am getting Seg Fault whenever I try to retrieve the thread name.

avatar image DarkwindRichard Sep 07 '18 at 06:21 PM

If you are getting an error on PlayStation, I would suggest making a post over on UDN.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question