Increase Score when a goal is scored
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:
The image below is where I'm assuming I have to make a reference to the object within either of the two custom events:
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:
Thanks for the help in advance, sorry if I have not provided enough information, feel free to ask for more if it's needed
asked Mar 22 '19 at 07:49 PM in Using UE4
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.
answered Mar 22 '19 at 09:07 PM
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.
answered Mar 22 '19 at 08:07 PM
Nebula Games Inc
Follow this question
Once you sign in you will be able to subscribe for any updates here