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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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. http://prntscr.com/33mzwi

Product Version: Not Selected
Tags:
more ▼

asked Mar 24 '14 at 09:23 AM in C++ Programming

avatar image

Leeroy712
1 3 5 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

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: http://herbsutter.com/2013/05/22/gotw-5-solution-overriding-virtual-functions/ And MSDN has the basic warning information here: http://msdn.microsoft.com/en-us/library/ay4h0tc9.aspx And finally a pretty good explanation of the rationale here: http://stackoverflow.com/questions/1628768/why-does-an-overridden-function-in-the-derived-class-hide-other-overloads-of-the

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 :)

more ▼

answered Mar 24 '14 at 02:37 PM

avatar image

Marc Audy STAFF
2.2k 42 35 95

avatar image BiggestSmile Mar 24 '14 at 03:03 PM

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

avatar image Marc Audy STAFF Mar 24 '14 at 03:32 PM

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.

avatar image BiggestSmile Mar 24 '14 at 08:22 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hey, thank you for the feedback but i've tried and the end is this.... http://prntscr.com/33njxj this is the .h file and the the cpp shots. 1 http://prntscr.com/33nk92 and second http://prntscr.com/33nkcp

more ▼

answered Mar 24 '14 at 11:25 AM

avatar image

Leeroy712
1 3 5 8

avatar image BiggestSmile Mar 24 '14 at 11:49 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Still happening. I have no ideea why is it happening... http://prntscr.com/33ntoh.

more ▼

answered Mar 24 '14 at 12:32 PM

avatar image

Leeroy712
1 3 5 8

avatar image BiggestSmile Mar 24 '14 at 12:41 PM
 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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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 .

more ▼

answered Mar 24 '14 at 01:11 PM

avatar image

Leeroy712
1 3 5 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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