UPawnSensingComponent has 2 virtual functions I want to override. Here’s my class:
UCLASS()
class MYPROJECT_API UCancellaPawnSensingComponent : public UPawnSensingComponent
{
GENERATED_BODY()
public:
virtual bool CouldSeePawn(const APawn* Other, bool bMaySkipChecks = false) const override;
virtual void SensePawn(APawn& Pawn) override;
};
The CPP definitions:
bool UCancellaPawnSensingComponent::CouldSeePawn(const APawn* Other, bool bMaySkipChecks) const
{
//my code
}
void UCancellaPawnSensingComponent::SensePawn(APawn& Pawn)
{
// my code
}
The problem is that when I use this class into my UCharacter subclass, the two functions do not seem to be overridden. The Super version is executed. I can also trigger breakpoints in the Super version of the function. Is there something I am doing wrong in the way I override the functions?
Edit: an update on the problem.
The problem disappears if I create the object in the constructor of my character as so:
SensingComponentPtr = CreateDefaultSubobject<UCancellaPawnSensingComponent>("MySensingComponent");
The problem is there if I create the object at runtime as so:
SensingComponentPtr = NewObject<UCancellaPawnSensingComponent>(this, SensingComponentPtr->StaticClass());
So I guess there is something about NewObject that I don’t understand.