What’s the difference?
If your project grows, this would make it easier to maintain.
I just need to assign the result of dividing two numbers to a variable.
Is your Widget Blueprint inheriting from your class? Does the Progress Bar have the same name ‘Bar’?
You can change the Parent Class in your Widget Blueprint > Graph > Class Settings > ( Details ) Parent Class.
I need the health bar to correspond to the value of the Health variable, which is constantly changing. How to do this in C++?
The easiest way would be for you:
- Create the UserWidget in C++.
- Store the variable created by the function.
- Create a public function in UHealthBar to set the progress value.
- Call this function from your other class.
I don’t have examples in C++, before I did, but now I find it easier to leave the visual part in Blueprint.
Creating User Widget:
https://docs.unrealengine.com/4.27/en-US/API/Runtime/UMG/Blueprint/CreateWidget/
You need to store the variable returning from this function ( C++ or Blueprint ) to change its values.
Example:
https://forums.unrealengine.com/t/createwidget-c/462559/2