Referencing Actor in a Widget Blueprint

Hi, I have a Ball actor which destroys Cube actors in game. I want to increase a score every time a Cube is destroyed. Score is a Text Widget. I think my problem is in referencing Ball actor in the Score Blueprint. Here’s what I have so far:

First, I made a widget in Ball BP:

Then I made a function for counting score. This is in Ball BP as well:

(This function currently prints the score as string on the screen. It’s for testing purposes before the Text Widget is working)

Then I created Widget BP and added a Text widget for score. I set it as a variable called Score. I also made function called UpdateScore which increments the score. I have this function connected to the Event Tick of the Score BP:

The thing is that I get the score updated each frame on this way. Each frame the function UpdateScore increases score by 1. But I have a problem when I try to make my Ball object update the score by 1 once the Cube is destroyed. I tried to do it on this way:

This is how I tried to call and reference Ball Actor in the Score BP, but I get the warning that you can see on the picture. I assume that this warning is the reason why I can’t update the score once I destroy the cube. But here’s also the modified UpdateScore function which now calls Ball actor and uses variables from it.

I tried adding the Ball actor reference and then getting the ScoreVar, which is variable from the second image that keeps the score in the Ball BP which prints score correctly on the screen via Print String. But instead of getting the updated score each time a cube is destroyed I just get the initial value, which is zero, once I start my game.

So can you please tell me what am I doing wrong here? I’m beating my head pretty much the whole day on this thing and I still couldn’t solve it. I read many things on here, but some of them use some stuff that I still haven’t learned so I don’t know how to implement it. This is my first time trying to do something in Blueprints.

Also the third image where I only use logic inside Score BP without calling anything from Ball actor is just to see and show that everything is set up properly for score to update but that the referencing and calling from Ball actor is where I made a mistake and don’t know how to do. So, the last two images are a problem.

Thank you in advance, and sorry for long post.

Also, I forgot to mention but Ball is not my Player Pawn, but I use Player Pawn to shot the ball that destroys the cubes.

You are struggling with the basic concepts of casting and creating references. You need to cast to your ball BP from the widget to access variables within the ball. You could easily use the score variable from the ball BP to update the widget text directly instead of having 2 separate variables. Also, updating on “tick” isn’t necessary and odd since the player can’t score points that fast. Check out this playlist. There are a few videos that go over the issues you are having. First is casting (#1), references (#25) and finally there is one going over a “scoring system” (#10) which is exactly what you are doing here. Hope these help.

1 Like

Thank you for your answer, those tutorials were really helpful, now I understand referencing and casting clearly. Yeah, the second variable and use of Tick was just for testing to see if the score will update without Ball, since I didn’t know how to update it by referencing the Ball.

I did it on the following way, in case someone else is having the same problem:

This is how I reference the Ball actor to widget.

This is how the score gets updated.

Thank you for your reply.

2 Likes