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"

Getter value not being pulled through

Hi,

I am trying to increase my score when an overlap event occurs, the code is called correctly but the value contained within the overlapped actor is not being pulled through.

For example, I spawn a powerup into the scene, it's powerupvalue is set to 50

alt text

When the overlap event happens, I call the following line of code:

 void APaddle::BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
 {
     if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
     {
         APowerup* const CollidedPowerup = Cast<APowerup>(OtherActor);
         if (CollidedPowerup)
         {
             SetScore(CollidedPowerup->GetPowerupValue());
             UE_LOG(LogTemp, Warning, TEXT("Current Score: %d"), GetScore());
             CollidedPowerup->Destroy();            
         }
     }
 }

The destroy part of the code works, but the value of the log always returns 0. If I run the following line of code within this snippet of code:

 UE_LOG(LogTemp, Warning, TEXT("Powerup Score: %d"), CollidedPowerup->GetPowerupValue());

The value returned is also 0, but if I spawn a powerup and check it's properties in Details tab as mentioned above, I can see that the powerup value is set to 50.

Why is this happening?

Product Version: UE 4.22
Tags:
powerupvalue.png (3.0 kB)
more ▼

asked Apr 21 '19 at 06:04 PM in C++ Programming

avatar image

JayFitz91
1 3 1 5

avatar image JayFitz91 Apr 21 '19 at 06:52 PM

Just an update to say the CurrentScore is successfully updated on my player actor when I check the Details tab, it just seems to be in the editor it is not updating

avatar image JayFitz91 Apr 22 '19 at 11:31 AM

I've been trying to troubleshoot why this is not working and I'm fairly certain its a bug/UI issue. I created a widget that keeps track of the score by using the GetScore() function. When I collect a powerup, the UI widget updates correctly, so it is only the editor which displays the incorrect value

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

1 answer: sort voted first

I found out why this is not working, I was using the wrong formatting value. My CurrentScore variable is a float so I should have been using %f in the Text. %d is used for integers so if I change the line of code from

 UE_LOG(LogTemp, Warning, TEXT("Current Score: %d"), GetScore());

to

 UE_LOG(LogTemp, Warning, TEXT("Current Score: %f"), GetScore());

The Output Log displays the correct value, more information can be found on the Unreal Wiki below:

https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime

more ▼

answered Apr 22 '19 at 12:35 PM

avatar image

JayFitz91
1 3 1 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