Hi guys, I’m stuck again with trying to increase the score every time a goal is scored. Right now when the ball overlaps the object, it runs one of two custom events from an external function as seen in this image:
This function is working and fires correctly as the print string shows, however I also need it to increase the score for either Red Team or Blue Team. I have set up the function that binds the text but cannot seem to get the text to update when the goal is scored:
You need to somehow get a reference to the Car_UI widget. Not sure where this widget is located (3D widget component, viewport etc) but that will determine how you get the reference. Post some more screen shots of how you create this widget and where it is located and I will be able to give you a better answer of how to reference it. You can also check out video #25 in this series about creating references that might give you some tips.
This video also shows how to reference a 3D widget component (albeit from another widget) but you can use the same method to reference a 3D widget in any BP if your widgets are 3D components of other actors.
Also, I see I helped you with a prior referencing issue with this series. Anything in particular different about this one you couldn’t figure out from the videos? The last video is a different one FYI if maybe that was the issue. If not let me know what the trouble is with the references here.
You are correct, to call the function in your widget you need to get a reference to it. The best way to do this is to store a reference to the widget when it is created and added to the viewport (this is usually done in the PlayerController or HUD). Once you have the reference you can call your text update function.
I have a couple of comments about your project setup which you might like to take note of.
I see you are using your Ball blueprint to keep track of current scores. This might be problematic if your ball is destroyed or if you spawn a new ball, since that is where all your information is stored. I would recommend moving “BlueGoalCount” and “RedGoalCount” variables to your GameMode along with the events you use to register if a goal has been scored.
It is good practice to not store game information in world objects, keep this information in your game object classes like PlayerController, GameModes, GameInstances etc.
Once your GameMode has the score information, you can then loop through your player controllers and ask them update their UI.
One final comment, you don’t need to use an bound function to update your UI text, you can access the text node directly (providing it is marked as variable) or bind the text widget to a text variable.
Thanks for the help! I decided to re-watch the video and it helped a lot, I used what you put there along with the help of the other answer and made it work