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"

Updating 2D image of dice result in realtime - Paper 2D, UMG or HUD?

Hey all, I'm in the process of creating a dice based game and want to go from displaying the dice results as an integer on screen to a 2D image of the dice. I've tried normal HUD and UMG so far, in UMG I'm not sure how to swap the displayed image in real-time and for each instance of dice. I've tried laying multiple UMG images on top of each other and using ZOrder to choose which is on top, this hasn't worked though.

As for 'traditional' HUD I have a working implementation but only for a single die, I can't get multiple instances of the resulting image to display. I've tried using a loop to call the function in which the image is drawn but that just updates the original instance.

It's just come across my mind that maybe I should be using Paper 2D for this sort of HUD element, but I though I'd ask here first before I spend the time implementing it.

Many Thanks

Product Version: UE 4.11
Tags:
more ▼

asked Apr 11 '16 at 11:16 AM in Rendering

avatar image

BoggartBear
3 1 3

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

1 answer: sort voted first

I would recommend using the UMG, HUD is outdated and Paper2D is a plugin that you probably don't need in the project.

Changing active texture is actually quite simple: add Image to you UMG widget, and expose it (add name and click the box). Then, inside graph editor, get reference to that UMG element and SetBrushFromTexture to swap the textures (I am talking from memory, names could be a bit different).

I hope this helps

more ▼

answered Apr 11 '16 at 11:31 AM

avatar image

ziga.osolin
206 9 12 76

avatar image BoggartBear Apr 11 '16 at 11:46 AM

Oh my that worked! I've tried many different implementation I've found online and this is the only one to work and is by far the simplest. I must have missed something some where haha. Thanks a lot.

Do you mind me asking one more question?

There are 6 dice, each being an instance of class 'SingleDie'. I want to display the 2D result for each die separately, I can use GetAllActorsOfClass and ForEachLoop but the problem is that each time the dice are rolled the actor names change. For example the first roll of dice are called SingleDie1 through SingleDie6 then the second roll is SingleDie7 through SingleDie12 etc.

How can I assign each UMG image representation to each die.

Thanks again.

avatar image ziga.osolin Apr 11 '16 at 12:00 PM

You should never refer to name of the instance, as they can be changed. In each class (blueprint or C++), create a variable (like dice index) and use that instead of the name to identify. You can still use foreach, but I would recommend using it only in construct because it is slow if you do it each frame. There, you can filter them by index.

Alternatively (depending on you design), widgets could be spawned by the SingleDie using a reference to the correct one. This is a strategy if behaviour, and positioning, is known ahead of time.

avatar image BoggartBear Apr 11 '16 at 12:08 PM

Thanks for the answer, could you elaborate on the first method if you have time? I am using the same method of spawning the dice as the PuzzleGrid template included in UE4.

As for the second method, I am currently using a single UMG Widget to store all aspects of the HUD. Would this method involve have separate widgets for each die? Each widget having just the UMG Image and no other HUD element.

I am still very new to UE4 so I am sorry for the perhaps stupid questions, Thanks.

EDIT: Perhaps just this in sequence after all the dice have been created? Dice Index

avatar image ziga.osolin Apr 11 '16 at 12:23 PM

Yes, that could definitely work. Here, you assign unique IDs. In your widgets, you have 6 images and you can do the same loop to figure out which die class goes with which image (again for loop and branch where die index and "widget index" are compared). Just note that every time you roll dices, you need to assign those indices that make them unique. Also, you should destroy previous rolls before you assign as it might happen that all are alive. You can also reuse rolls (the same class, have a function Reroll that creates a new value/changed 3d representation).

Apart from that, just make something that works I guess. There is no right or wrong here, especially for simple games that do not need so many performance optimizations.

avatar image BoggartBear Apr 11 '16 at 12:29 PM

Okay thanks a lot for the help. I think this question can be closed. :)

(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