UMG, overriding of UsingWidget.Tick

Hello!

UserWidget.Tick is not virtual, could I somehow override Tick in my derived class?

Dima.

I think it’s wierd that the staff hasn’t commented on this yet. I’m noticing that in the head file it even says

/**
	 * Ticks this widget.  Override in derived classes, but always call the parent implementation.
	 *
	 * @param  MyGeometry The space allotted for this widget
	 * @param  InDeltaTime  Real time passed since last tick
	 */

There is no way to actually override it…

See my answer to another posting:

But in 4.8 its now throwing a warning C4996: ‘UUserWidget::Tick_Implementation’: Use NativeTick Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
But the NativeTick is still not virtual! I have no idea what they are doing…

.h

virtual void NativeTick(const FGeometry& MyGeometry, float DeltaTime) override;

.cpp

void UMainMenuWidget::NativeTick(const FGeometry& MyGeometry, float DeltaTime)
{
	Super::NativeTick(MyGeometry, DeltaTime);

        // Your code goes here
}
5 Likes

It may be better to leave the c++ code above the Super::NativeTick call, because it calls the blueprint Tick, and if it relies on things set by c++ the variables may not be up to date.

I find it best practice to always call Super::NativeTick (or any overrided virtual method, for that matter).
If you need something done in C++ before the blueprint, simply place the code before the call. You could also have bool bReady in your class definition, and then:

void UMyWidget::NativeTick(const FGeometry& MyGeometry, float DeltaTime) {
    Super::NativeTick(MyGeometry, DeltaTime);
    if(!bReady)
        return;
    // Do whatever
}

I wasn’t able to override the NativeTick as described above in 4.26. It just says
“void UUserWidget::NativeTick(const FGeometry &,float)’: no override available for virtual member function from base class virtual member function’”
And
‘UUserWidget’;"‘UCollectionDetailPanel::NativeTick’: method with override specifier ‘override’ did not override any base class methods"