Crouch function in C++

Hello guys,

I’ve been programming in UC for a while and now when U4 came out we decided to move our game into U4 for various reasons, and i’m struggling a little. I could use some help if it’s not a big deal.

I’m trying to implement 2 functions into my game, crouching and sprinting which depletes over 10 seconds.

My crouching script is like this

I appologize for the wall of text. sorry.

in Character.h i’ve declared:

    UFUNCTION()
	void OnStartCrouch();
UFUNCTION()
	void OnEndCrouch();

and in the Character.cpp i’ve implemented :

InputComponent->BindAction(“Crouch”, IE_Pressed, this, &ADejaVuCharacter::OnStartCrouch);
InputComponent->BindAction(“Crouch”, IE_Released, this, &ADejaVuCharacter::OnEndCrouch);

void ADejaVuCharacter::OnStartCrouch()
{
bIsCrouched = true;
CrouchedEyeHeight = true;
}

void ADejaVuCharacter::OnEndCrouch()
{
bIsCrouched = false;
CrouchedEyeHeight = false;
}

yet when i’m compiling i get this. Screenshot by Lightshot

Hey, thank you for the feedback but i’ve tried and the end is this… Screenshot by Lightshot this is the .h file and the the cpp shots. 1 Screenshot by Lightshot and second Screenshot by Lightshot

They’re declared w/o UFUNCTION macro, try removing it. Sorry i’m not that much into objects system myself yet.

No, that’s not right

Still happening. I have no ideea why is it happening… Screenshot by Lightshot.

virtual void OnStartCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust);
virtual void OnEndCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust);

This is how they’re declared, you’re basically not overriding anything actually. I’ve never worked with UE3 before, so i have no experience at all, but are you sure you have to override these methods? Seems like everything is handled in ACharacter.

Took a look on GameFramework a bit. You should bind your Crouch button to ACharacter::Crouch, bIsCrouched is handled within UCharacterMovement component. To make a crouch animation you should edit corresponding AnimBlueprint the way you want, JumpEnd JumpStart states from third-person example would be a starting point here.

Jumping is also implemented in ACharacter and animation controlled via blueprint. To make a character sprint/walk i simply set CharacterMovement variable “MaxWalkSpeed” to various values. I’ve set walking speed to 100 and running sprint to 450, it fits my “ideas”. You might want to edit blendspace little bit to make a smoother look of animations.

smile do you have a skype account where we could talk a little ? I’m starting to loose hope here. and seriously thank you for all the help so far. or you add me on skype at ionut7122

Smile can you please add me on skype if you can. ionut7122 i’m seriously starting to loose all hope on this. and thank you soo mch for all the help so far .

This is a C++ issue. Because ACharacter defines OnStartCrouch as a virtual function in the base class but you have a non-virtual function of the same name in the subclass, you are inadvertently hiding the base class function.

You can read a bit more about it here in improvement #3: GotW #5 Solution: Overriding Virtual Functions – Sutter’s Mill
And MSDN has the basic warning information here: Compiler Warning (level 4) C4263 | Microsoft Learn
And finally a pretty good explanation of the rationale here: c++ - Why does an overridden function in the derived class hide other overloads of the base class? - Stack Overflow

The easy solution is just rename your OnStartCrouch/OnEndCrouch functions to something else.

EDIT: Added some extra links and clarifications, I must say I didn’t know about this particular behaviour, so I learned something new today while looking in to this :slight_smile:

Thank you, for voting my answer down, which advices to use virtual keyword, while you’re saying exactly the same :slight_smile:

Not exactly, your suggestion won’t actually compile because the OnStartCrouch() without parameters doesn’t override anything as the base class has two float parameters. What Leeroy712 is trying to do is respond to an input event and thus it must have an empty parameter list. Because of the (kind of weird) C++ standard he will need to rename his functions so they don’t hide the base class.

You also could check my comment below. But whatever, that was sorted out hours ago, and information you’ve provided had nothing to do with it.