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"

How to get a camera manager from another script? c++

Hello! I was wondering how it would be possible to get a player camera manager into a script so that I can edit the cameras rotation. Thanks! -Ian

Product Version: Not Selected
Tags:
more ▼

asked Mar 25 '16 at 06:22 PM in C++ Programming

avatar image

Designer102
86 18 19 25

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Assuming this is for single player game, you can get the camera manager like this:

 if (GetWorld())
 {
     AYourCustomCameraManager* CameraManager = Cast<AYourCustomCameraManager>(UGameplayStatics::GetPlayerCameraManager(GetWorld(), 0));
 if (CameraManager )
    {
         // CameraManager->DoStuff();
    }
 }
more ▼

answered Mar 25 '16 at 06:35 PM

avatar image

ryanjon2040
1.6k 55 43 92

avatar image Designer102 Mar 25 '16 at 10:25 PM

No, this is for a multiplayer fps game. It uses the shooter game example.

avatar image ryanjon2040 Mar 26 '16 at 05:19 AM

For a multiplayer game, you can iterate through all the player controllers and get the player camera manager class and cast it to your custom type by using below code:

 for (FConstPlayerControllerIterator ControllerIterator = GetWorld()->GetPlayerControllerIterator(); ControllerIterator; ++ControllerIterator)
     {
         const APlayerController* PlayerController = *ControllerIterator;
                 
         if (PlayerController && PlayerController->IsLocalController())
         {
             const AYourCustomCameraManager* CameraManager = Cast<AYourCustomCameraManager>(PlayerController->PlayerCameraManager);
             if (CameraManager)
             {
                 // CameraManager->DoStuff();
             }
         }
     }

Just remember that in a multiplayer game, clients are ONLY aware of their own PlayerController and Server has access to ALL player controllers. When the above code is executed on client, it will return only one controller but when executed on server it will get all the controllers and therefore we make sure it will run only on the server player by using IsLocalController().

(comments are locked)
10|2000 characters needed characters left
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