So I’m still fairly new to Unreal, and right now I’m trying to implement a double jump into the 2D sidescroller template, but when I jump, Unreal crashes immediately. I’m trying to override the CanJump() function so that it will allow the player to jump twice. I also override the Landed() function so that it will reset the jump count.
Here is the body of my character header file.
GENERATED_BODY()
UFUNCTION()
void OnStartJump();
UFUNCTION()
void OnStopJump();
/** Side view camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera, meta=(AllowPrivateAccess="true"))
class UCameraComponent* SideViewCameraComponent;
/** Camera boom positioning the camera beside the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
protected:
// The animation to play while running around
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Animations)
class UPaperFlipbook* RunningAnimation;
// The animation to play while idle (standing still)
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Animations)
class UPaperFlipbook* IdleAnimation;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Movement")
int32 MaxJumpCount;
UPROPERTY()
int32 CurrentJumpCount;
/** Called to choose the correct animation to play based on the character's movement state */
void UpdateAnimation();
/** Called for side to side input */
void MoveRight(float Value);
bool CanJumpInternal_Implementation() const override;
virtual void Landed(const FHitResult& Hit);
/** Handle touch inputs. */
void TouchStarted(const ETouchIndex::Type FingerIndex, const FVector Location);
/** Handle touch stop event. */
void TouchStopped(const ETouchIndex::Type FingerIndex, const FVector Location);
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
// End of APawn interface
public:
AJunglePlatformerCodeCharacter();
/** Returns SideViewCameraComponent subobject **/
FORCEINLINE class UCameraComponent* GetSideViewCameraComponent() const { return SideViewCameraComponent; }
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
Here’s the important bits of my character’s cpp file:
bool AJunglePlatformerCodeCharacter::CanJumpInternal_Implementation() const
{
return Super::CanJump() || (GetCharacterMovement()->MovementMode == MOVE_Falling && CurrentJumpCount > 0 && CurrentJumpCount < MaxJumpCount);
}
void AJunglePlatformerCodeCharacter::OnStartJump()
{
bPressedJump = true;
CurrentJumpCount++;
}
void AJunglePlatformerCodeCharacter::Landed(const FHitResult& Hit)
{
CurrentJumpCount = 0;
}
void AJunglePlatformerCodeCharacter::OnStopJump()
{
bPressedJump = false;
}
If anyone can find anything that immediately pops out as a crash-causer, please let me know.