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"

Crash when calling GetController or GetCharacterMovement

Hi everyone, for some reason I'm having a problem which makes the entire editor crash.

I have a basic PlayerController class that binds to input axises. Inside the functions for the handling of input I call some functions such as MoveHorizontal/MoveVertical etc. from a possessed Character class. Inside those function I just get the character movement component object of the class and use AddInputVector to modify the movement of the character.

Now, while everything is working fine for single player purposes.. the entire editor crashes when I try to play in a multiplayer environment. As a matter of fact, I can't even check for the presence of a null pointer since the GetCharacterMovement itself crashes immediately.

Does anyone have any clue what this could be?

Product Version: UE 4.10
Tags:
more ▼

asked Jan 22 '16 at 09:05 AM in C++ Programming

avatar image

DiG
16 2 3 7

avatar image cancel Jan 22 '16 at 09:48 AM

Hi, could you post the code? The .h and .cpp files would help me find what might be going wrong.

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

1 answer: sort voted first

If this->GetCharacterMovement() crashes immediately, then your 'this' value is not valid. Somehow you've managed to get a pointer to a non-existent player controller or character.

As the other guy said, post your code.

more ▼

answered Jan 22 '16 at 11:38 AM

avatar image

TTaM
1.7k 79 28 81

avatar image DiG Jan 22 '16 at 06:18 PM
 void ABasePlayerController::HorizontalMovement( float _x_axis )
 {
     ABasePlayerCharacter* pawn = Cast<ABasePlayerCharacter>( GetPawn() );
     check( pawn ); // The assert fails here. Only in Multiplayer though
     if ( pawn != nullptr )
     {
         pawn->MoveHorizontal( FMath::Clamp( _x_axis , -1.0f , 1.0f ) );
     }
 }

I've narrowed the error down to the pawn pointer inside the controller having a null value (or at least some problem with it). The assert fails if the game is played in multiplayer. However, if I remove the check(pawn) and just leave the check for nullptr the game works properly. Thing is, I've also tried and used an else whose code block never gets called.

This problem NEVER happens in single player.

avatar image TTaM Jan 22 '16 at 07:38 PM

Whose player controller are you calling that on? Only the owning client's PC gets replicated to the client, so if you try to use another client's, it will be null and that method will fail.

(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