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"

Server to client variable delay

Hello, I've got a question regarding variable replication. I created a SpectatorPawn, which is possessed by a player as soon as he dies. Since it's not a free-to-fly spectator, but a spectator mode, where you can only observe your teammates (similar to Counter-Strike) I've put two replicated variables into my Custom Player State holding the current postition and the current rotation of the player pawn, the playerstate is connected to. The replication itself does work and I'm able to observe another player. The problem, however, is that the SpectatorPawn only gets the updated variables once per second, which causes major "lag" in the camera movement. See this:

https://www.youtube.com/watch?v=PGJ0mgdXrvc∈dex=3&list=PL5xr2OpsFu2EiAHGVU7FggsOmj3lNbWVn

This only happens, when a client is the observer. If the server is observing another player the location and rotation get updated very smoothly. See this:

https://www.youtube.com/watch?v=wQcEu-F3FfY&list=PL5xr2OpsFu2EiAHGVU7FggsOmj3lNbWVn∈dex=4

So basically the client versions of my Spectator Pawn only get updates every second. Why is this?

Here are my cpp files and the associated blueprints:

Spectator-Pawn void AShooterSpectatorPawn::OnStartFire() { ++iIndex; ObservablePawns.Reset(); for (int32 i = 0; i < GetWorld()->GameState->PlayerArray.Num(); ++i) { AShooterPlayerState* plState = Cast(GetWorld()->GameState->PlayerArray[i]); AShooterCharacter* Pawn = Cast(plState->StatePawn); if (!plState->bIsABot) { if (Pawn) { / See if the Pawn is still alive / if (Pawn->IsAlive()) { / If yes add it to observable pawns / ObservablePawns.Add(Pawn); ObservablePSs.Add(plState); } } } }

     if (ObservablePawns.Num() > 0)
     {
         /* Make sure you loop through the observable array and don't run beyond it */
         if (iIndex >= ObservablePawns.Num())
         {
             iIndex = 0;
         }    
 
         GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, TEXT("Index: ") + FString::FromInt(iIndex));
         ObservedPawn = ObservablePawns[iIndex];
         ObservedPlayerState = ObservablePSs[iIndex];
     }
 }
 
 void AShooterSpectatorPawn::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
 {
     if (ObservedPlayerState)
     {
         OutResult.Rotation = ObservedPlayerState->MyRotation;
         OutResult.Location = ObservedPlayerState->MyLocation;
     }
 }

MyPlayerState.h

     UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadWrite, Category = PlayerPawn)
         FVector MyLocation;
 
     UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadWrite, Category = PlayerPawn)
         FRotator MyRotation;

MyPlayerState.cpp

 void AShooterPlayerState::GetLifetimeReplicatedProps( TArray< FLifetimeProperty > & OutLifetimeProps ) const
 {
     Super::GetLifetimeReplicatedProps( OutLifetimeProps );
 
     DOREPLIFETIME(AShooterPlayerState, TeamNumber);
     DOREPLIFETIME(AShooterPlayerState, NumKills);
     DOREPLIFETIME(AShooterPlayerState, NumDeaths);
     DOREPLIFETIME(AShooterPlayerState, MyRotation);
     DOREPLIFETIME(AShooterPlayerState, MyLocation);
 }


PlayerPawn Blueprint:

alt text

I don't know where the problem is and what to do. Does anyone of you know, why this is happening?

Thanks in advance Max

Product Version: Not Selected
Tags:
more ▼

asked Oct 06 '14 at 12:40 PM in C++ Programming

avatar image

PT_Max
23 5 10 11

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

1 answer: sort voted first

SpectatorPawn

 void AShooterSpectatorPawn::OnStartFire()
 {
     ++iIndex;
     ObservablePawns.Reset();
     for (int32 i = 0; i < GetWorld()->GameState->PlayerArray.Num(); ++i)
     {
         AShooterPlayerState* plState = Cast<AShooterPlayerState>(GetWorld()->GameState->PlayerArray[i]);
         AShooterCharacter* Pawn = Cast<AShooterCharacter>(plState->StatePawn);
         if (!plState->bIsABot)
         {
             if (Pawn)
             {
                 /* See if the Pawn is still alive */
                 if (Pawn->IsAlive())
                 {
                     /* If yes add it to observable pawns */
                     ObservablePawns.Add(Pawn);
                     ObservablePSs.Add(plState);
                 }
             }
         }
     }
 
     if (ObservablePawns.Num() > 0)
     {
         /* Make sure you loop through the observable array and don't run beyond it */
         if (iIndex >= ObservablePawns.Num())
         {
             iIndex = 0;
         }    
 
         GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, TEXT("Index: ") + FString::FromInt(iIndex));
         ObservedPawn = ObservablePawns[iIndex];
         ObservedPlayerState = ObservablePSs[iIndex];
     }
 }
more ▼

answered Oct 06 '14 at 12:43 PM

avatar image

PT_Max
23 5 10 11

(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