Download

Another newbie question again... this time -> Tick in the actor component.

Sorry to post another question in the forum by few hours, but I face different kind of problem right now… which I predict it is newbie mistake, yet I have no idea how to solve it properly.

In C++, I have own class (derived from AActor class) with my own actor component (i named it as Character_Stat) , which is being stored with many stats, such as Action Bar.

Action Bar? Honestly I don’t know the proper name for it, but when you play old Final Fantasy, there is a progress bar that refills by time and when it is fully filled, your character can be selected…

I think you get what I mean from it. Okay, I used to implement that similar style in Unity (my forte is not Unity anymore -_-),

however in Unreal, when I approach with different style - with actor component, my actor component tick does not work and not add up my Action Bar with delta time.

I remember now that… I created Blueprint from that class, and adding that component inside BP. is it because I used BP? if it is the case, How can I activate tick from that component?

To add up, when I use Tick Event in BP Graph, I can use only one exec line… which i need more for animation (set flip book) and stat (to add that action bar, which only BP can trigger tick…)…

It sounds complicated… but even simple Tick does not work for my project, which is troublesome because it is essential for my battle system and having limited time (few days… Sob) to implement the battle system.

I only wanted to create simple FF ish game… Pretty Please…



virtual void TickComponent() override;


I can’t remember what the arguments are (whether it only takes DeltaSeconds or if it takes the TickType / TickLevel too), but that’s the function you need to override and implement. Standard ActorComponents don’t tick by default, so you have to enable it by adding this in the classes constructor:



PrimaryComponentTick.bCanEverTick = true;
PrimaryComponentTick.bStartWithTickEnabled = true;


okay thank you so much. i will try again with your code!

I added those code in my actor component class (even as UDefault_Character_Stat::UDefault_Character_Stat(const FObjectInitializer& ObjectInitializer)). in my BP of the actor class, it is not adding my action bar… that means… that tickComponent does not work properly by some reason… i gotta find it asap… anyway thank you :slight_smile:

You need to override this function :




//header
public:

    void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;

//cpp

void UMyAwesomeComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
 {
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
     //Do awesome stuff
 }

Also don’t forget to add (after @TheJamsh say) in the constructor bAutoActivate and bAutoRegister to true :slight_smile:

Thank you with another info. After I exclude “virtual” and adding “enum” inside the parameter… I also added bAutoActivate and bAutoRegister as true. but my action bar (or tick component) does not add up with delta time… what is wrong with my coding :frowning:

it is killing me… if i get that tick done, i can finish battle system roughly by today

is it because only BP does not show what I want? I am doubtful about BP…

I think I gonna cry (well literally)… I will have coffee break… I never expect TickComponent will jeopardize my project in unexpected way… but i don’t hate Unreal… just self loathing -_-; Darn. I guess I am too newbie than i thought.

I think you can just use blueprints to implement what you are talking about…

From the tick event, you can use the Sequence node to split into multiple exec lines to fire off multiple things

Also, your action bar is probably be implemented using UMG. If so, one approach is to bind the percent fill of the action bar to a custom function in the UMG whichc reads the property. This is called automatically ever tick.

Good Luck

Thanks. I think I am going try again as fiddling with c++ for few hours… if I don’t get what I want, I think I will use blueprint to do all things. I am kinda desperate. It is all or nothing in this short time now. Unless I can persuade fellow team member to wait… which cannot be happening.

well… time is too short… i decided move those variables (like HP) from actor component to actor class… i will come up with solution about Tick Component in Actor component later… now I am really… in “Bad Time” (From Sans, Undertale). Thanks to my newbie programming and unwise thoughts in limited time. (no one to blame… cuz it is purely my fault… and yeah… it is my own project :P)

edit -> forgot to say “Thank you” to those who aided me with reply and solutions. it has been awesome!

Isn’t it sufficient with this code?

.h



virtual void Tick(float DeltaTime) override;


.cpp



AYourActorComponent::Tick(float DeltaTime) {
Super::Tick(DeltaTime);

}


The Super call to Tick is important, otherwise you won’t tick.

Marjane, I wanted to chime in and suggest that perhaps your problem is not stemming from the Tick function. Maybe check if Tick is working by adding some debug output to the definition:



AYourActorComponent::Tick(float DeltaTime)
{
     Super::Tick(DeltaTime);

     UE_LOG(LogTemp, Warning, TEXT("AYourActorComponent is Ticking."))  // This will write debug text to the output console, so you can check and see if it's being called properly!
}

If you’ve done this and the output console displays the log message (about a million times ;)), then you know your problem is elsewhere.

omg u r right

. i never thought super could cause trouble.

QUOTE=MPalacios;520843]Isn’t it sufficient with this code?

.h



virtual void Tick(float DeltaTime) override;


.cpp



AYourActorComponent::Tick(float DeltaTime) {
Super::Tick(DeltaTime);

}


The Super call to Tick is important, otherwise you won’t tick.
[/QUOTE]

You should nearly always call Super when you override engine functions or you’re likely to get odd behaviour. It’s pretty rare that you don’t do it.

well, i was in hurry and am still newbie. Thus thanks for telling me.

thanks, but my compiler says “What is Tick? oh you should use TickComponent”… uh… btw i checked code and it was already included with Super… I am clueless like few weeks ago