Keep pawn crouched when possessing

Hey Gang,

My game has two characters that the player switches between during gameplay. I’m running into a small issue when unpossessing and possessing a pawn. If I crouch the character (using the built-in UE4 crouch functionality) and then unpossess the pawn, when I repossess the character the crouch gets cancelled and they just stand up.

Any thoughts on how to get around this? My current band-aid is to store whether or not the character is crouched in a bool and then run the crouch event when “Event Possessed” is called, but there’s an issue with that: If you run the crouch event directly off of the possessed event then it doesn’t fire. You can put a 0.0000001 second delay on it, and it’ll fire almost as instantaneously as if it were firing directly, but then you end up getting a “standing position to crouching” animation when you switch back to the character which is pretty yucky.

Any tips would be super appreciated.

Thanks!

Thought I would give this a bump as it’s gone unanswered for several weeks.

I am also having this issue in 4.14.3, any help with it?

AI controller fires Uncrouch on Possessed. Only way to fix it is not using the built-in UE4 crouch functionality. It’s usually a bad thing. Just create custom variable and bind your animation and logic to it.

You can override this behaviour in C++. Just override the ACharacter::Restart() function in a child class or remove the UnCrouch(true); command.

void ACharacter::Restart()
{
	Super::Restart();

    JumpCurrentCount = 0;

	bPressedJump = false;
	ResetJumpState();
	UnCrouch(true);

	if (CharacterMovement)
	{
		CharacterMovement->SetDefaultMovementMode();
	}
}

This is how you can override the function in ACharacter child class (in this case MyCharacter)

void MyCharacter::Restart()
{
	APawn::Restart();

	JumpCurrentCount = 0;

	bPressedJump = false;
	ResetJumpState();

	UCharacterMovementComponent* CharacterMovement = GetCharacterMovement();
	if (CharacterMovement)
	{
		CharacterMovement->SetDefaultMovementMode();
	}
}

After setting AI controller to none something is still firing Uncroach so I disagree. I use builting Crouch functionality and my workaround is to use my own Crouching bool variable to toggle between crouch and uncrouch. Then after possession, I check if the character was crouching before I switched to another character/pawn. If it was, then I invoke Crouch. The delay there is very important because after possessing a character/pawn, some nasty function sets the character build in isCrouched variable to false. But if I wait it out and crouch after that, then my character stays crouched after possession. Remember to use your own variable to trigger the crouch animation, otherwise the crouch animation will fire when you invoke the Crouch function.