Add Impulse work with key event and with c++ not

I call in c++ a blueprint Blueprint Implementable Event on the character from the character movement component for testing because it didn’t work… and for testing also a key evnet from character blueprint… (see screenshot)

My question is how I can find out why it works with key events and not with C++…

unreal engine 5.4.4

1 Like

Pressing N you are running SRVSLIDE on server. so the impulse will be added only if you press N in the server terminal (only if you are Owner, meaning you are the possesed pawn or local playercontroller)

You implemented an on Slide Ready C++ function but you are not showing how are you calling it.

I hope it’s readable

(post deleted by author)

I simply copied the entire crouch system from the character and character movement and used it for slide

1 Like

This might sound silly and apologies if it does, but have you bound the action to the function in your SetupInputComponent function in the PlayerController?

I connected the input action with InputTag

i use the lyra starter game

When I press the button, the capsule size is changed for server and other clients. However, only the add impulse doesn’t work

I’m struggling to see where you call AddImpulse, could you screenshot that for us please? :slight_smile:

on the second picture I call LyraCharacterOwner->OnSlideReady();

I only did this because it didn’t work the first time. That was the event in the first picture…

if it worked I wouldn’t use LyraCharacterOwner->OnSlideReady(); I would replace with AddImpulse function…

sorry for my bad google translate english… : )

a similar issu i have with jump… when i call in blueprint the character jump function with key event its work and in c++ when i call the function dosen´t work…

void ACharacter::Jump()
{
	bPressedJump = true;
	JumpKeyHoldTime = 0.0f;
}

an then i have add this line

	if (bPerformJump)
		{
			CharacterOwner->bPressedJump = true;
			CharacterOwner->CheckJumpInput(DeltaSeconds);
			bPerformJump = false;
		}

and without this CheckJumpInput dosent work… maybe i must someting similar make on AddImpulse

ok i have test it… in c++ directly in LyraCharacter call the Character function jump work (with the same InputTag)… and when i call on LyraCharacterMovmentComponent the same function dosent work

void ULyraCharacterMovementComponent::LyraMantle(bool bClientSimulation)
{
	LyraCharacterOwner->Jump();

	if(GEngine)
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("This is the pre-set text"));
}

the text are printed

LyraCharacter are so implement

void ULyraCharacterMovementComponent::InitializeComponent()
{
	Super::InitializeComponent();

	LyraCharacterOwner = Cast<ALyraCharacter>(PawnOwner);
}

Okay so Jump is actually super easy, you just need to call the virtual Jump function that lives in the ACharacter class, then call Super::Jump(), then it’ll work:

.h

virtual void Jump() override;

.cpp

void ALyraCharacter::Jump()
{
 Super::Jump();
// any extra functionality you want to add here, but this will work on its own
}

Show us how you would use the AddImpule function instead of OnSlideReady, it might be that you were missing something or calling it incorrectly :slight_smile:

thanks for the help… for the understanding…

i call with InputTag this function

void ALyraCharacter::ToggleMantle()
{
	Jump();
}

Character are jumping

and then i call this function

void ALyraCharacter::ToggleMantle()
{
	if (ULyraCharacterMovementComponent* LyraMoveComp = CastChecked<ULyraCharacterMovementComponent>(GetCharacterMovement()))
	{
		LyraMoveComp->LyraMantle();
	}
}
void ULyraCharacterMovementComponent::LyraMantle(bool bClientSimulation)
{
	LyraCharacterOwner->Jump();
}

Character are jumping and AddImpulse are also work (because only the client call this its flip back)

and then i call how i implement it

void ALyraCharacter::ToggleMantle()
{
	if (ULyraCharacterMovementComponent* LyraMoveComp = CastChecked<ULyraCharacterMovementComponent>(GetCharacterMovement()))
	{
		LyraMoveComp->bLyraWantsToMantle = true;
	}
}
void ULyraCharacterMovementComponent::UpdateCharacterStateBeforeMovement(float DeltaSeconds)
{
	if (LyraCharacterOwner->GetLocalRole() != ROLE_SimulatedProxy)
	{
		const bool bIsMantleing = LyraIsMantleing();
		if (bIsMantleing && !bLyraWantsToMantle)
		{
			LyraUnMantle(false);
		}
		else if (!bIsMantleing && bLyraWantsToMantle)
		{
			LyraMantle(false);
		}
	}
	
	Super::UpdateCharacterStateBeforeMovement(DeltaSeconds);
}

void ULyraCharacterMovementComponent::LyraMantle(bool bClientSimulation)
{
	LyraCharacterOwner->Jump();
}

Character are not Jump or AddImpulse

how I would AddImpulse implement it

void ULyraCharacterMovementComponent::LyraMantle(bool bClientSimulation)
{
	AddImpulse (FVector(0.0f, 1000.0f, 0.0f), true);
}

it looks that UpdateCharacterStateBeforeMovement broke it but i dont know why

Don’t misunderstand the function is called, I made sure of this using print screen…

Another thing to know is that I use safe variables and flags

I’ve now checked everything again and didn’t find any errors…
however I saw something new…

when I print the CharacterOwner display name the server has:
B_Hero_ShooterMannequin_C_1

and the client has:
B_Hero_ShooterMannequin_1

Shouldn’t the two have the same name??

ok, the C is not the problem… when I start via visual studio there is no C and when I only start the .uproject there is a C in both

I did the same as you and it worked.

thank you… it must be a mistake on my side…

(post deleted by author)

I finally have it with the function

void ULyraCharacterMovementComponent::OnMovementUpdated(float DeltaSeconds, const FVector& OldLocation,
	const FVector& OldVelocity)
{
	Super::OnMovementUpdated(DeltaSeconds, OldLocation, OldVelocity);

	if (bPerformSlide)
	{
		AddImpulse(FVector(0.0f, 0.0f, 1000.0f),true);
		bPerformSlide = false;
	}
}

I still don’t know why it doesn’t work with UpdateCharacterStateBeforeMovement…
but it is how it is

Many thanks to everyone who wanted to help