Random object material moved to widget

Hi I need help creating a mechanic in which the material from the object will be transferred to the widget on the frontier. In the blueprint with the object from which the material is to be taken, I have created a mechanic in which each time the game starts the material changes, and I would like to stick to this.

(Material that is randomized each time the game starts)

You can replace the 5 nodes with these:


But… what is the actual question here? Are the materials not showing up in the UI? If so, are they UI domain materials? You must give us something to work with :innocent:

So let’s say we have 3 cubes that change their material every time the game is started. And I would like these materials to be “copied” to the Widget. I hope this is clearer now, if not I will try to explain it in a different way

(A border is placed on the widget.)

Surface materials cannot be displayed in the UI domain (afaik - if someone knows a neat trick, do tell!)

  • this is a material that can sit on the cube:

  • and this is a UI material:

As you can see, these are two different creatures - hence the question in the previous post. You cannot copy one to the other or vice versa. The UI has no idea about PBR or what is happening to the light in the scene, for example.

You could make a set of 2 materials that closely resemble one another - have one on the cube and assign the other to UI. That could work and is relatively simple. But if you need just colours, you do not need a material in the widget - colour the border brush instead. Would that be enough or do you need the material to show more than a simple colour? Sending a texture could also work.

One way or another: ideally, look into how Dynamic Material Instances and their Parameters work, this would allow you to store a colour as a vector inside the cube material, fetch it and send that pure colour data to the widget. If you literally need 3 static colours only and nothing else - create 3 separate materials instead.

Regarding how to communicate this between actors ↔ widgets, there’s a dozen ways to do it. Assuming only the following:

we have 3 cubes that change their material every time the game is started. And I would like these materials to be “copied” to the Widget.

  • create a widget with 3 borders, exposed them as variables
  • create a material with a colour parameter
  • in the Level Blueprint, on Begin Play:
    – create and add a widget to the viewport
    – reference the cubes, add them to an array, shuffle it
    – create a dynamic material instance for each cube and feed its parameter a colour
    – use the same colour or read it off the cube → apply it to the widget’s border brush

You did not specify whether the order of the widgets / cubes matters.

Hmmm… maybe let’s try it another way, Let’s say for example we have a Structure (unless there is a better option to do it) that has various materials already stored in it. Let’s say it will be something like an order, we get it at the beginning of the game each time it is different and we have to collect objects (example these cubes) to win the game. I know it is a bit complicated now but I want everything in the game to work as it should, if something is not quite clear I will try to explain it differently, but anyway thanks for your answer

Sounds like a pretty straighforward puzzle:

  • make an array full of materials, shuffle on Begin Play
  • make a bunch of cubes using the same materials, the mats can be assigned randomly or randomise cube locations; or use as is since it’s random anyway
  • when running into / picking a cube, compare its material to the current entry in the array:
    – if it does not match, game over, lose a life, send the player a passive aggressive message :person_shrugging:
    – if it matches, increase the current iterator, destroy the cube (?), we score a point, etc…
    – if the iterator exceeds array bounds, we win

Btw, here’s an example of what I described in the previous post:

Every time you start the game the cube order gets randomised:

You can randomise the widget order instead or in addition to. A matching colour is used in the material and the widget brush. This would be better set up with some kind of ID system, perhaps an enumerator. Comparing colours is clumsy from the programming point of view.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.