We can find an example of using a UObject in several areas of the source code. My example comes from AbilityTask_Repeat.cpp in the Gameplay Abilities modules. Here we have a time set on the ability task.
GetWorld()->GetTimerManager().SetTimer(TimerHandle_PerformAction, this, &UAbilityTask_Repeat::PerformAction, TimeBetweenActions, true);
TimeBetweenActions is a float member variable.
TimerHandle_PerformAction is an FTimerHandle structure.
What you are missing is the ‘this’ parameter in your second code example.
So your code should be:
.SetTimer(FadeTimerHandle, this, &UGameManager::SwitchScreen, 0.5f, true);
Also, if you are getting access violations during runtime, your objects may be going out of scope or you may have invalid pointers. GetWorld() returns a pointer, so make sure that the GetWorld() return’s a valid pointer by checking against nullptr. Also make sure that you are not destroying the object (UGameManager) after setting the timer and make sure it is not destroyed before the timer callback is called.