x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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->GetWorld(), 0);
 APlayerController* b = UGameplayStatics::GetPlayerController(GWorld->GetWorld(), 0);
 APlayerController* c = UGameplayStatics::GetPlayerController(GEngine->GetWorld(), 0);
 APlayerController* d = UGameplayStatics::GetPlayerController(GEditor->GetEditorWorldContext().World(), 0);

Product Version: UE 4.21
Tags:
more ▼

asked Dec 09 '18 at 05:58 PM in C++ Programming

avatar image

SweeneyPro
8 3 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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);
more ▼

answered Dec 14 '18 at 09:40 AM

avatar image

SweeneyPro
8 3 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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?

more ▼

answered Dec 09 '18 at 06:24 PM

avatar image

Shadowriver
36.6k 931 169 1111

avatar image SweeneyPro Dec 09 '18 at 07:20 PM

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->GetWorld(), 0);
     APlayerController* a = UGameplayStatics::GetPlayerController(GWorld->GetWorld(), 0);
     APlayerController* c = UGameplayStatics::GetPlayerController(GEngine->GetWorld(), 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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question