Skip to content

Commit

Permalink
Generify FieldGetter so it works with any type
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Aug 22, 2024
1 parent d3c5422 commit 2a17076
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Source/UEST/Private/UESTGameInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
// UGameInstance::WorldContext is not public, and neither InitializeStandalone nor InitializeForPlayInEditor is suitable for us.
// So we use this template hack to access WorldContext field.
// Source: https://ledas.com/post/857-how-to-hack-c-with-templates-and-friends/
template<FWorldContext* UGameInstance::*WorldContext>
struct Stealer
{
static friend FWorldContext*& FieldGetter(UGameInstance& GameInstance)
{
return GameInstance.*WorldContext;
template<typename T, auto T::* Field, typename RetVal>
struct Stealer {
static friend RetVal& FieldGetter(T& Object) {
return Object.*Field;
}
};

template struct Stealer<&UGameInstance::WorldContext>;
template struct Stealer<UGameInstance, &UGameInstance::WorldContext, FWorldContext*>;
static FWorldContext*& FieldGetter(UGameInstance&);

void IUESTGameInstance::DefaultInitializeForTests(UGameInstance& GameInstance, const bool bRunAsDedicated, const int32 PIEInstance)
Expand Down

0 comments on commit 2a17076

Please sign in to comment.