# Unable to override functions in UPawnSensingComponent

**URL:** <https://forums.unrealengine.com/t/unable-to-override-functions-in-upawnsensingcomponent/474917>\
**Category:** Community & Industry Discussion\
**Tags:** override, newobject, unreal-engine, question\
**Created:** [November 23, 2020, 8:12pm UTC](https://forums.unrealengine.com/t/unable-to-override-functions-in-upawnsensingcomponent/474917 "2020-11-23T20:12:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nyquisttt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nyquisttt](https://forums.unrealengine.com/u/Nyquisttt)\
**Post date:** [November 23, 2020, 8:12pm UTC](https://forums.unrealengine.com/t/unable-to-override-functions-in-upawnsensingcomponent/474917/1 "2020-11-23T20:12:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nyquisttt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nyquisttt](https://forums.unrealengine.com/u/Nyquisttt)\
**Post date:** [November 24, 2020, 2:53pm UTC](https://forums.unrealengine.com/t/unable-to-override-functions-in-upawnsensingcomponent/474917/2 "2020-11-24T14:53:26Z")

</div>

I have found a solution, although I am not sure about the implications. Anyway, after using NewObject on SensingComponentPtr pointer I need to use RegisterComponent:

```
SensingComponentPtr->RegisterComponent();

```

Hope this helps someone else.
