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"

SetViewTarget On Unpossess

Hi everyone

I am currently writing a game where when the current pawn dies it should select a random camera actor in the level and set it as viewtarget until the player can respawn. Unfortunately I am running into an issue.

Desired behaviour:

  1. Player dies

  2. Random Camera is selected as new view target

Easy as that

Code:

Here is the relevant code

 void APlayerControllerC::OnUnPossess()
 {
     Super::OnUnPossess();
     //Need to add guard, if player controller is destroyed
     if (!IsPendingKillPending()) {
         SetViewportToCamera();
     }
 }
 
 void APlayerControllerC::SetViewportToCamera(bool blend)
 {
     //Has Autority guard
     if (HasAuthority() && GetWorld()) {
         ACameraActor* Camera = GetRandomCamera()
         if (Camera) {
             if (blend) {
                 SetViewTargetWithBlend(Camera, 0.5);
             }
             else {
                 SetViewTarget(Camera);
             }
         }
     }
 }

 // Here SetViewportToCamera works
 void APlayerControllerC::SetTeam_Implementation(int i)
 {
     if (GetWorld()) {
             DoStuff()
         SetViewportToCamera();
     }
 }

Actual behaviour

All functions are called including SetViewTargetWithBlend in every occasion but there is no effect on screen. The camera stays in place where the pawn was unpossessed.

The function SetViewportToCamera works fine when called from other functions (See Code)

Any Ideas?

Product Version: UE 4.22
Tags:
more ▼

asked Apr 25 '19 at 12:06 PM in C++ Programming

avatar image

bldy_ch
6 1 2

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

1 answer: sort voted first

I solved the problem

I had to set the bAutoManageActiveCamera in the PlayerController to false. Unfortunately this does not seem to be changeable at runtime. So I have to set the viewtarget manually whenever I possess a pawn.

Not a perfect solution, but still a solution.

more ▼

answered Apr 27 '19 at 02:45 PM

avatar image

bldy_ch
6 1 2

(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