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"

Random Text UMG

Hi guys! I have a game (Block Forest) where you roll around as a ball. when you hit an enemy, you die. I was wondering (not critical or anything) if there was a way to do random text on my UMG game over widget. Example: First time you die it might say, "You were eaten by aliens" Second time, "You exploded" etc. Thanks!

Product Version: UE 4.12
more ▼

asked Jul 07 '16 at 05:03 PM in Blueprint Scripting

avatar image

Im A Hefty Lad
6 1 3 6

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

1 answer: sort voted first


Here's how I set this up (granted, it's not exactly the same as yours. I create my widget on a key press instead for testing purposes, so when you see the F key press, replace that with your death event.)

First, let's set up the widget:

I added a simple Text component to my widget blueprint, and set Is Variable to true, as well as set Size To Content to true as you'll see in the screenshot below. Also, keep in mind that you'll need to set your canvas panel to Desired by selecting the Fill Screen tab at the top right of the viewport and changing it to Desired. Ensure that you've anchored your text how you'd like to do so as well. I anchored mine to the center for testing.

alt text

Next, you'll want to set up the Event Graph of your Widget Blueprint. This is where your logic will take place. Since you checked the Is Variable box on your Text, you should see it in the Variables panel of the Details panel. Drag a reference into the graph and call SetText. Here's the fun part, create a new variable of type String (or Text) and make it an array. Add as many elements as you'd like to this array. This is where you will put your game over messages.

alt text

Once you have done this, drag a reference to the array into your event graph, and pull off a Get node. Off of the integer input, add a Random Integer in Range node and set the Min and Max values to correspond with the number of elements in your array. Finally, connect this to the Set Text node.

alt text

The last step is to go into your character blueprint and actually create the widget. I used the FirstPersonCharacter blueprint since this was a test project, but you can use whatever you are using for your player character.

What I did was: On key press, or death event in your case, I created the widget, added it to the viewport, and then removed the widget after a short delay so it doesn't remain on the screen (you may need to customize this part to fit your needs as well).

alt text

This should get you the random results you're looking for as far as pulling different game over messages goes.

Let me know if you have any questions about the setup.

Have a great day!

widgetsetup.png (84.0 kB)
array.png (46.8 kB)
settext.png (88.7 kB)
more ▼

answered Jul 07 '16 at 05:21 PM

avatar image

Sean L ♦♦ STAFF
43.5k 485 152 442

avatar image DDemon Jul 07 '16 at 05:33 PM

Wow nice answer, Good job.

avatar image Im A Hefty Lad Jul 07 '16 at 05:41 PM

Yes awesome I will try it. Thanks!

avatar image Im A Hefty Lad Jul 07 '16 at 06:03 PM

Worked perfectly first try. Thanks so much.

(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