Hello,
I have tick event in my pawn class and for debugging purpose I am printing a message on to the log screen. The problem is that the message is printed twice per run. I also have a blueprint inheriting the c++ class which too has an event tick.
So if this is due to the blueprint tick calling its parent tick , how do I prevent it?
So if i need to prevent the tick from running twice I need to add the second option in my pawn class but doing the negation of it like
if(! (this.GetCkass().GetClassFlags() & CLASS_NATIVE ) )
I will explain you how it works, when in C++ you call Super::Tick()
inside AActor class ReceiveTick()
is called which is triggers event in blueprint, so bot blueprint and C++ will be called, there no way to override C++ function with blueprint event, so you need to put that in account. You should not remove Super::Tick()
, because this will not only make tick not work in blueprint as ReceiveTick()
won’t be called, it will also disable tick in other parent C++ classes which might be needed for them to function properly.
So best option is simply not duplicate code in C++ and blueprint, but if you really can’t prevent that you can do things like those:
if(this.GetClass() = AYourPawnClass::StaticClass) {
//your code here
}
if(this.GetClass().GetClassFlags() & CLASS_Native) {
//your code here
}
first option will prevent parent execution even in C++, 2nd will prevent tick execution only when class is a blueprint