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"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Crash after custom CharacterMovementComponent

I implemented a custom CharacterMovementComponent yesterday and everything worked fine, even between editor sessions, meaning I closed the editor down and opened it up serveral times...

but today when I tried to fire the project up I got a crash at startup, went into debug and the Character class would crash when running the K2_OnMovementModeChanged becuase it tries to run CharacterMovement-> which is null at this point...

 void ACharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PrevCustomMode)
 {
     if (!bPressedJump || !CharacterMovement->IsFalling())
     {
         ResetJumpState();
     }
 
     // Record jump force start time for proxies. Allows us to expire the jump even if not continually ticking down a timer.
     if (bProxyIsJumpForceApplied && CharacterMovement->IsFalling())
     {
         ProxyJumpForceStartedTime = GetWorld()->GetTimeSeconds();
     }
 
     K2_OnMovementModeChanged(PrevMovementMode, CharacterMovement->MovementMode, PrevCustomMode, CharacterMovement->CustomMovementMode);
     MovementModeChangedDelegate.Broadcast(this, PrevMovementMode, PrevCustomMode);
 }

I have reverted all the code and deleted the "CustomCharacterMovement" class. Everything is exactly as it was before but now I dont crash at start up, but when I try to click the Character in the scene, (which is a blueprintclass based on the character in cpp) I crash. Assertion failed: IsViewportValid()

I can run several other editor projects without any issue so it cant be a hardware problem...

CustomCharacter.h

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Character.h"
 #include "CustomCharacter.generated.h"
 
 UCLASS()
 class MY_API ACustomCharacter : public ACharacter
 {
     GENERATED_BODY()
 
 public:
     ACustomCharacter(const class FObjectInitializer& ObjectInitializer);
 
     // ...
     
     virtual void OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode = 0) override;

CustomCharacter.cpp

 #include "MyGame.h"
 #include "CustomCharacter.h"
 #include "CustomGameMode.h"
 #include "CustomMovementComponent.h"
 
 ACustomCharacter::ACustomCharacter(const class FObjectInitializer& ObjectInitializer)
         : Super(ObjectInitializer.SetDefaultSubobjectClass<UCustomMovementComponent>(ACharacter::CharacterMovementComponentName))
     {
         // ...
     }
     
     void ACustomCharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode)
     {
         Super::OnMovementModeChanged(PrevMovementMode, PreviousCustomMode);
     
         if (PrevMovementMode == EMovementMode::MOVE_Falling && 
             GetCharacterMovement()->MovementMode != EMovementMode::MOVE_Falling)
         {
             SetIsJumping(false);
         }
     }
 

CustomMovementComponent.h

 #pragma once
 
 #include "GameFramework/CharacterMovementComponent.h"
 #include "CustomMovementComponent.generated.h"
 
 UCLASS()
 class MY_API UCustomMovementComponent : public UCharacterMovementComponent
 {
     GENERATED_BODY()
 
     virtual float GetMaxSpeed() const override;
 
 };

CustomMovementComponent.cpp

 #include "MyGame.h"
 #include "CustomMovementComponent.h"
 #include "CustomCharacter.h"
 
 float UCustomMovementComponent::GetMaxSpeed() const
 {
     float MaxSpeed = Super::GetMaxSpeed();
 
     const ACustomCharacter* CharOwner = Cast<ACustomCharacter>(PawnOwner);
     if (CharOwner)
     {
         if (CharOwner->IsTargeting() && !IsCrouching())
         {
             MaxSpeed *= CharOwner->GetTargetingSpeedModifier();
         }
         else if (CharOwner->IsSprinting())
         {
             MaxSpeed *= CharOwner->GetSprintingSpeedModifier();
         }
     }
     return MaxSpeed;
 }


Do anyone know what might have caused this? I find it strange that even reverting all the code back to the way it was before is still not making it work? Someone please...

Product Version: UE 4.21
Tags:
more ▼

asked Feb 06 '19 at 01:49 PM in C++ Programming

avatar image

Ko0zi
1 2

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

1 answer: sort voted first

I'm was using an Editor built from source, Eventually I downloaded a fresh editor from the launcher and had no problems what so ever. How strange is that? I'll leave a picture of the call stack if that would be interesting to someone.

Solved for now anyways, I'll try to build a new engine from the same source as before and se if that will work.

more ▼

answered Feb 06 '19 at 02:44 PM

avatar image

Ko0zi
1 2

(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