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"

Trying to override base class methods, getting error C3668

I was following survival sample game tutorial about Sprinting and sharing it to all clients. And I am trying to use same method for my character but trying to put combat mode on

I use parent character to define all inputs and put the combat mode on and then im using Base character to set it on to other clients.

The problem is that this

 virtual void SetCombatMode(bool NewCombatMode) override
 {
 }

should override this

 virtual void SetCombatMode(bool NewCombatMode);

but when trying to compile it says this error

 error C3668: 'AFpCharacter::SetCombatMode': method with override specifier 'override' did not override any base class methods

here is my both characters classes

parent character .h

 #include "BaseFpCharacter.h"
 #include "FpCharacter.generated.h"
 
 void C_ModeToggle();

 virtual void SetCombatMode(bool NewCombatMode) override
 {
 }

parent character .cpp

 #include "FP_Duel.h"
 #include "FpCharacter.h"
 #include "engine.h"
 #include "BaseFpCharacter.h"

 void AFpCharacter::C_ModeToggle()
 {
     SetCombatMode(true);
 }

and Base character .h

 #include "project.h"
 #include "Net/UnrealNetwork.h"
 #include "BaseFpCharacter.generated.h"
 
 public:
 
 UFUNCTION(BlueprintCallable, Category = "Movement")
     virtual bool IsCombatMode() const;
 
     virtual void SetCombatMode(bool NewCombatMode);
 
 UPROPERTY(Transient, Replicated)
     bool bWantsCombatMode;
 
 protected:
 
     UFUNCTION(Reliable, Server, WithValidation)
     void ServerCombatMode(bool NewCombatMode);
     void ServerCombatMode_Implementation(bool NewCombatMode);
     bool ServerCombatMode_Validate(bool NewCombatMode);
 
     virtual void Tick(float DeltaSeconds) override;

base character .cpp

     #include "BaseFpCharacter.h"
     #include "DuelGameMode.h"
 
 void ABaseFpCharacter::SetCombatMode(bool NewCombatMode)
  {
     bWantsCombatMode = NewCombatMode;
     
     if (Role < ROLE_Authority)
     {
     ServerCombatMode(NewCombatMode);
     }
 }
 
     void ABaseFpCharacter::Tick(float DeltaTime)
     {
     
     Super::Tick(DeltaTime);
     
     if (bWantsCombatMode && !IsCombatMode())
     {
     SetCombatMode(true);
     }
     
 }

Thanks for help

Product Version: UE 4.13
Tags:
more ▼

asked Sep 21 '16 at 11:17 PM in C++ Programming

avatar image

Sven97
5 2 2 4

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

2 answers: sort voted first

Did you specify that your AFpCharacter inherit from ABaseFpCharacter ?

in AFpCharacter.h

 class AFpCharacter: ABaseFpCharacter
 {
 public:
    ....
 
 }
more ▼

answered Sep 22 '16 at 05:33 AM

avatar image

Draykoon
111 4 4 5

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

It's tough to see what's going on without the full contents of the source files. You say you want AFpCharacter to be the "parent", but if it's the parent then ABaseFpCharacter should be overriding its methods, not the other way around. Do you mean that AFpCharacter is supposed to be the child?

If this is the full content of the source files, there's a number of problems here. Without the class declarations there's no tie into your API, UE4 macros, or Blueprints (if you want access to them in Blueprints); on top of the fact that you're not actually creating a new class.

Your method definition in the FpCharacter.h file is declaring an empty method within the header; you can place it here, but you probably just want a semi-colon (;) after "override" and to place the body of the function (assuming there is one) in the .cpp file.

So this:

 #include "BaseFpCharacter.h"
  #include "FpCharacter.generated.h"
      
  void C_ModeToggle();
      
  virtual void SetCombatMode(bool NewCombatMode) override
  {
  }

Should look more like this:

 #include "BaseFpCharacter.h"
 #include "FpCharacter.generated.h"
          
 UCLASS()
 class YOURGAME_API AFpCharacter : public ABaseFpCharacter {
     
     GENERATED_BODY()
     
     //constructor
     AFpCharacter();
     
     void C_ModeToggle();
     
     virtual void SetCombatMode(bool NewCombatMode) override;
     
 };


If you want your class to be available in Blueprint you'll want to include "Blueprintable" and "BlueprintType" in your UCLASS macro:

 UCLASS(Blueprintable, BlueprintType)


Your FpCharacter.cpp file should go from this:

 #include "FP_Duel.h"
  #include "FpCharacter.h"
  #include "engine.h"
  #include "BaseFpCharacter.h"
  
  void AFpCharacter::C_ModeToggle()
  {
      SetCombatMode(true);
  }

To this:

  #include "FP_Duel.h"
  #include "FpCharacter.h"
  #include "engine.h"
  #include "BaseFpCharacter.h"
  
 //Constructor
 AFpCharacter::AFpCharacter()
     :
     ABaseFpCharacter()
 {}
 
 void AFpCharacter::C_ModeToggle()
  {
      SetCombatMode(true);
  }
 
 void AFpCharacter::SetCombatMode(bool NewCombatMode)
  {
     //include method functionality here; assuming you want to do
     //something with the boolean;

     //if you want to add to the functionality of the parent method
     //rather than replacing it, be sure to include:
     Super::SetCombatMode(NewCombatMode)
 
  }

Similarly, your BaseFpCharacter needs a class declaration, macros etc. I'm assuming you want to inherit from ACharacter, but you could also use APawn or AActor

 #include "project.h"
 #include "Net/UnrealNetwork.h"
 #include "BaseFpCharacter.generated.h"
 
 UCLASS(Blueprintable, BlueprintType)
 class YOURGAME_API ABaseFpCharacter : public ACharacter
 {
     GENERATED_BODY()
 
     public:
 
     //constructor
     ABaseFpCharacter(); 
 
     UFUNCTION(BlueprintCallable, Category = "Movement")
     virtual bool IsCombatMode() const;
      
     virtual void SetCombatMode(bool NewCombatMode);
      
     UPROPERTY(Transient, Replicated)
     bool bWantsCombatMode;
  
     protected:
      
     UFUNCTION(Reliable, Server, WithValidation)
     void ServerCombatMode(bool NewCombatMode);
     void ServerCombatMode_Implementation(bool NewCombatMode);
     bool ServerCombatMode_Validate(bool NewCombatMode);
      
     virtual void Tick(float DeltaSeconds) override;
 
 };

Then your BaseFpCharacter.cpp fill will need to include the constructor:

 ABaseFpCharacter::ABaseFpCharacter()
     :
     ACharacter()
 {}
 

more ▼

answered Sep 22 '16 at 08:23 AM

avatar image

GigasightMedia
1.7k 43 13 61

avatar image Sven97 Sep 22 '16 at 09:01 AM

sorry I should have said that I had all Constructors. problem was the FpCharacter.h header

 UCLASS()
 class FP_DUEL_API AFpCharacter : public ABaseFpCharacter
 {
     GENERATED_BODY()

(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