UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CocoaThread.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5
6#define MAC_SEPARATE_GAME_THREAD 1 // Separate the main & game threads so that we better handle the interaction between the Cocoa's event delegates and UE's event polling.
7
8/* Custom run-loop modes for Unreal that process only certain kinds of events to simulate Windows event ordering. */
9CORE_API extern NSString* UnrealNilEventMode; /* Process only mandatory events */
10CORE_API extern NSString* UnrealShowEventMode; /* Process only show window events */
11CORE_API extern NSString* UnrealResizeEventMode; /* Process only resize/move window events */
12CORE_API extern NSString* UnrealFullscreenEventMode; /* Process only fullscreen mode events */
13CORE_API extern NSString* UnrealCloseEventMode; /* Process only close window events */
14CORE_API extern NSString* UnrealIMEEventMode; /* Process only input method events */
15
16#if MAC_SEPARATE_GAME_THREAD
19#endif
20
21@interface NSThread (FCocoaThread)
22+ (NSThread*) gameThread; // Returns the main game thread, or nil if has yet to be constructed.
23+ (bool) isGameThread; // True if the current thread is the main game thread, else false.
24- (bool) isGameThread; // True if this thread object is the main game thread, else false.
25@end
26
27@interface FCocoaGameThread : NSThread
28- (id)init; // Override that sets the variable backing +[NSThread gameThread], do not override in a subclass.
29- (id)initWithTarget:(id)Target selector:(SEL)Selector object:(id)Argument; // Override that sets the variable backing +[NSThread gameThread], do not override in a subclass.
30- (void)dealloc; // Override that clears the variable backing +[NSThread gameThread], do not override in a subclass.
31- (void)main; // Override that sets the variable backing +[NSRunLoop gameRunLoop], do not override in a subclass.
32@end
33
43
44UE_DEPRECATED(5.6, "Use the alternative with inverted last parameters")
49
57template<typename ReturnType>
58ReturnType MainThreadReturn(ReturnType (^Block)(void), NSString* WaitMode = NSDefaultRunLoopMode)
59{
60 __block ReturnType ReturnValue;
61 MainThreadCall(^{ ReturnValue = Block(); }, true, WaitMode);
62 return ReturnValue;
63}
64
74
75UE_DEPRECATED(5.6, "Use the alternative with inverted last parameters")
80
88template<typename ReturnType>
89ReturnType GameThreadReturn(ReturnType (^Block)(void), NSArray* SendModes = @[ NSDefaultRunLoopMode ])
90{
91 __block ReturnType ReturnValue;
92 GameThreadCall(^{ ReturnValue = Block(); }, true, SendModes);
93 return ReturnValue;
94}
95
96CORE_API void RunGameThread(id Target, SEL Selector);
97
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
CORE_API NSString * UnrealResizeEventMode
Definition CocoaThread.cpp:18
CORE_API NSString * UnrealNilEventMode
Definition CocoaThread.cpp:16
CORE_API void MainThreadCall(dispatch_block_t Block, bool const bWait=true, NSString *WaitMode=NSDefaultRunLoopMode)
Definition CocoaThread.cpp:457
CORE_API void ProcessGameThreadEvents(void)
Definition CocoaThread.cpp:514
CORE_API void RunGameThread(id Target, SEL Selector)
Definition CocoaThread.cpp:487
ReturnType MainThreadReturn(ReturnType(^Block)(void), NSString *WaitMode=NSDefaultRunLoopMode)
Definition CocoaThread.h:58
CORE_API NSString * UnrealCloseEventMode
Definition CocoaThread.cpp:20
CORE_API NSString * UnrealFullscreenEventMode
Definition CocoaThread.cpp:19
CORE_API void GameThreadCall(dispatch_block_t Block, bool const bWait=true, NSArray *SendModes=@[NSDefaultRunLoopMode])
Definition CocoaThread.cpp:474
ReturnType GameThreadReturn(ReturnType(^Block)(void), NSArray *SendModes=@[NSDefaultRunLoopMode])
Definition CocoaThread.h:89
CORE_API NSString * UnrealShowEventMode
Definition CocoaThread.cpp:17
CORE_API NSString * UnrealIMEEventMode
Definition CocoaThread.cpp:21
CORE_API uint32 GMacMainThreadId
Definition CocoaThread.cpp:24
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
const bool
Definition NetworkReplayStreaming.h:178
uint32_t uint32
Definition binka_ue_file_header.h:6
bool isGameThread()
Definition CocoaThread.cpp:314
NSThread * gameThread()
Definition CocoaThread.cpp:305
Definition CocoaThread.cpp:328
int main()
Definition radaudio_mdct_build_tables.cpp:83