Binding text via UMG failing
So I have a random name generator that fires every time I spawn in a new enemy AI so it can assign them a random name.
The function exists in the construction graph of the enemy AI and it functions properly as I am able to print the results to the screen.
I create an AI health bar and text (for name) via UMG. I am casting in the results of the bar and it functions well. But I am binding the textfield so I can grab the randomly generated name. I am casting in the BP that holds the name and the binding function is throwing no errors. But at runtime it fails every time.
asked Jan 02 '17 at 05:27 PM in Blueprint Scripting
The Object you are casting in "screen shot 2017-01-02 at 11.20.23 am.png" is called healthBar. So I assume it is a REF to a UMG? If so this is your error. It needs to be a REF to your enemyshipActor instead.
answered Jan 12 '17 at 10:31 AM
Although your method may work, it isn't very efficient. When you spawn your enemy ship, the name generator should be activated by the Event Begin Play event in your enemy ship blueprint as this is triggered when the ship comes into existence in the world; activating it via the construction script is not very efficient. (If you need the name and health to update in editor, not game, then you will need to do it in the construction script)
The pirate ranks and pirate names arrays should probably be stored on either your GameMode or Game State, to make them easier to access. (This is what i've done in my example)
You should then store this name in a variable on your ship blueprint, either in a struct variable or just in a text variable.
See below set up in enemy ship blueprint:
Setting the variable in the widget: Add an enemy ship variable to your widget, of type 'your enemy ship blueprint'. Then in the ship when you open the widget, pass the reference to the enemy ship through to the widget and store that in a variable.
Where ever you open the UMG, set the variable in the following way:
You can then bind the property for the text directly instead of going through binding functions.
This way is more efficient and allows you to directly bind ANY property on your ship to the widget without any further coding.
See below how to bind directly through variable stored on widget:
answered Dec 14 '17 at 06:42 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here