How can I access player character from PhysLevel.cpp

I’m trying to adjust the gravity direction for “simulate physics” from inside of the PhysLevel.cpp. I get an access violation upon building.

#include "GameFramework/Character.h"
#include "Kismet/GameplayStatics.h"

ACharacter* tempMainChar = UGameplayStatics::GetPlayerCharacter((), 0);
	// Update gravity in case it changed
	FVector DefaultGravity((tempMainChar->GetActorLocation().GetUnsafeNormal() * GetGravityZ()) * -1.f);

	static const auto CVar_MaxPhysicsDeltaTime = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("p.MaxPhysicsDeltaTime"));
	PhysScene->SetUpForFrame(&DefaultGravity, DeltaSeconds, UPhysicsSettings::Get()->MaxPhysicsDeltaTime);

Am I doing this right? (obviously not)

In what function it is in? I suspect () is a returning NULL

You are correct, I just saw that. Okay so this is inside of the PhysLevel.cpp - SetupPhysicsTickFunctions. I’m trying to fetch the player characters location and use that for my gravity system. I guess the character doesn’t exist yet?

So I think what I’m looking for is a location where the world is set, the player character exists and is accessible, and “simulate physics” has just taken over. Right when it starts. Currently I can modify the FVector inside of PhysLevel.cpp and the gravity after the game starts and simulation is going on will change the direction. I need to be able to modify this value from then on. Any ideas where this would be located?

I tried doing something like this and now it’s going into the “else” part and that would mean it isn’t returning Null right?

if (!())
{
	FVector DefaultGravity(0.f, 0.f, GetGravityZ());

	static const auto CVar_MaxPhysicsDeltaTime = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("p.MaxPhysicsDeltaTime"));
	PhysScene->SetUpForFrame(&DefaultGravity, DeltaSeconds, UPhysicsSettings::Get()->MaxPhysicsDeltaTime);
}
else
{
	UWorld* World = ();
	ACharacter* tempMainChar = UGameplayStatics::GetPlayerCharacter(World, 0);
	FVector DefaultGravity = tempMainChar->GetActorLocation();
	DefaultGravity.Normalize();
	DefaultGravity *= GetGravityZ() * -1.f;

	static const auto CVar_MaxPhysicsDeltaTime = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("p.MaxPhysicsDeltaTime"));
	PhysScene->SetUpForFrame(&DefaultGravity, DeltaSeconds, UPhysicsSettings::Get()->MaxPhysicsDeltaTime);
}

So what I did here is make a secondary tick method that just goes in afterwards to set the vector to what I need it. This lets me have one physics object (in simulatation mode) . The class calls the method in its tick to force it. Later I’ll have to find a way to have each physics scene hold a list of bodies with each body containing its own direction of gravity.