x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

alt text

Product Version: UE 4.12
Tags:
more ▼

asked Jan 02 '17 at 05:27 PM in Blueprint Scripting

avatar image

mikezteh69
37 7 9 11

avatar image mikezteh69 Jan 02 '17 at 10:09 PM

Man this is a tough one because I have been searching the webs all day and the only thing I think I am missing is what object is not linked up in the cast...

avatar image mikezteh69 Jan 03 '17 at 03:36 AM

So I got this to work...but I am not sure it is the best practice... So let me share.

So in the bind function event I created a function that runs the name generation script and holds all the data for the names. Then in the bind I fire that event and get the variable holding the name.

I feel like this is not a clean way to do this and I would rather there be a central location for this data so the function can be used in other ways and I kind of like the data structs to be exposed the in the enemy AI class but it does function. So I would like to change my original question to - IS THIS a good way of doing this?alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Jan 12 '17 at 10:31 AM

avatar image

Adnoh
177 4 7 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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: alt text

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: alt text

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: alt text

more ▼

answered Dec 14 '17 at 06:42 PM

avatar image

Neverlandadventure
6 1 4 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question