x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

TickComponent fails to call member functions

I'm having this weird issue where my TickComponent function is not calling other member functions in the same class.

The following works fine:

 void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
 {
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
     if (!HealthBarWidget) return;
     HealthBarWidget->SetHealth(HealthPoints);
     HealthBarWidget->SetMaximumHealth(MaximumHealthPoints);
     ElapsedTime += DeltaTime;
     if (ElapsedTime > 2.f)
     {
         HealthPoints -= 100;
         ElapsedTime = 0;
     }
 }

But the following doesn't:

 void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
 {
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
     if (!HealthBarWidget) return;
     DrainHealth(DeltaTime);
     UpdateWidget();
 }

 void UHealthComponent::DrainHealth(float deltaTime)
 {
     ElapsedTime += deltaTime;
     if (ElapsedTime > 2.f)
     {
         MutateHealth(-100);
         ElapsedTime = 0;
     }
 }

 void UHealthComponent::UpdateWidget()
 {
     if (!HealthBarWidget) return;
     HealthBarWidget->SetHealth(HealthPoints);
     HealthBarWidget->SetMaximumHealth(MaximumHealthPoints);
 }

 void UHealthComponent::MutateHealth(int32 deltaHealthPoints)
 {
     HealthPoints -= deltaHealthPoints;
 }


What's really weird is that the debugger will hit the breakpoint where the function is called but it won't actually step into the function. The functions just aren't getting called at all.

Can anyone point me in the right direction? Also: they all have the same access modifier: protected.

Product Version: UE 4.15
Tags:
more ▼

asked May 13 '17 at 02:23 AM in C++ Programming

avatar image

toxicg0d
34 3 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Even though the optimizer was indeed inlining my functions, there was a bug in my code that caused me to think the functions weren't working at all... I caught this by using #pragma optimize and stepping through my code.

 HealthPoints -= deltaHealthPoints

should instead be

 HealthPoints += deltaHealthPoints

Silly me.

more ▼

answered May 13 '17 at 04:03 AM

avatar image

toxicg0d
34 3 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question