Getting APlayerController from a plugin?

does anyone know how to fetch a player controller from within an editor plugin? None of the below work, they all return null and I’ve tried this in both editor and play in editor. I don’t believe any of the UGameplayStatics functions work from within a plugin. I think at one point i tried UGameplayStatics::GetAllActorsOfClass to get all the actors and still returned null.

APlayerController* a = UGameplayStatics::GetPlayerController(GEditor->(), 0);
APlayerController* b = UGameplayStatics::GetPlayerController(GWorld->(), 0);
APlayerController* c = UGameplayStatics::GetPlayerController(GEngine->(), 0);
APlayerController* d = UGameplayStatics::GetPlayerController(GEditor->GetEditorWorldContext().World(), 0);

There no difference between plugin and C++ project, only difference is you can attach you code to any project by enabling plugin.

PlayerController will only exist when game is played, so it depends on where you calling those functions, but if they are normal actors it should work if you call on typical event. So can you provide more details what you trying to do? where do oyu calling those functions?

I used the Editor Standalone Window plugin template and in the plugin clicked button function I try and get the player controller in the world.

void FRecorderModule::PluginButtonClicked()
{
	
	APlayerController* d = UGameplayStatics::GetPlayerController(GEditor->(), 0);
	APlayerController* a = UGameplayStatics::GetPlayerController(GWorld->(), 0);
	APlayerController* c = UGameplayStatics::GetPlayerController(GEngine->(), 0);
	APlayerController* e = UGameplayStatics::GetPlayerController(GEditor->GetEditorWorldContext().World(), 0);
	//UGameplayStatics::
	// Put your "OnButtonClicked" stuff here
	FText DialogText = FText::Format(
							LOCTEXT("PluginButtonDialogText", "Add code to {0} in {1} to override this button's actions"),
							FText::FromString(TEXT("FRecorderModule::PluginButtonClicked()")),
							FText::FromString(TEXT("Recorder.cpp"))
					   );
	FMessageDialog::Open(EAppMsgType::Ok, DialogText);
}

I could understand it not working in the editor if play is not active but doesn’t get the controller even if i start the game and then click the plugin button.

So for me the correct way to get the playercontroller is using the Geditor->PlayWorld which is a variable and not a function so the code is:

 APlayerController* a = UGameplayStatics::GetPlayerController(GEditor->PlayWorld, 0);