I need URGENT help. Random color material

Hi, would be very appreciated if someone helps. I’m doing my school project and I need to make cubes that have random color every time i start. These colors can’t match and one of them will be correct. What I mean is, at the of the game I have a widget, it must make the buttons be with the colors of the blocks and the third one is correct

I tried doing it using dynamic material instance but it doesn’t want to work(colors of the block doesn’t change). I can send the code I’ve done

Hi there, try explain what you are doing step by step, we help.

  1. You have 3 cubes in level?
  2. You have a widget with 3 boxes?
  3. You start the game, color of 3 cubes are different everytime.
  4. Also Everytime you start game, your widget 3 boxes match the cubes in the level?

So:

  • There are 5 boxes on the map
  • The widget has 5 buttons which must be the color of the boxes
  • Yes, when I start the game, color of these 5 cubes must be different(every cube has a unique color)
  • And yes, everytime I start the game, color of the buttons must match the color of the cubes
  • Also, there must be one correct color

Can you explain this also, so I can give you a very correct answer.

What exactly one correct color? if we have 5 cubes in level different colors and they match our boxes on widget, what is the one correct color? Don’t rush just trying to understand the problem entirely.

I mean, my game is labyrinth. I want to make that in the end of that labyrinth, there is a some kind of quiz. The question is “What was the *number*(for example 5) color you met in the maze?“. So, the game must choose one of five blocks, take it color and like mark it as a correct answer

UPD: I managed to do the random color thing(using dynamic materials), but they do not have unique colors and can be the same and I don’t really know how to do the other part of what I want

Gotcha,

1- So first things first your color material for cubes should be something like this.

2- I made a new blueprint class (actor) and put a cube inside, probably you have this

3- OnConstructionScript , I created a dynamic material instance (you did this seems), we need this cause without materials are simply static and shared. Created dynamic material and promoted it to a variable, then assign into cube back. So now it holds the dynamic material.

4- Created a new function as : SetCubeColor which simply gets the color and assigns to our static meshs dynamic material.

5- I created a variable LinearColor(rightClick variable to make array) as array and defined some colors. We get a random array item and assign it to cube by calling our newly created function.

6- Test : In my level I can see colors already assigned and random. However to make every cube unique color : how we do that?

7- So I get my actors for each and check if that color exists already in the level, if so we remove that and we get a cleaned colors, whatever we get from that array would be a new unique random color.

test , we have unique colors

8- So now you have random unique colors in level that we keep track of. I can get them like this and assign random / any of them as correct in my UI (in your scripts)

Let me know if this is enough information and you can get it done. Also if you get stuck don’t hesitate to ask.

Design thinking point : What if the player is color blind?

2 Likes

I have a question. Firstly, not so important but how do I make the connections of the nodes like you have?

Secondly, I’m not really sure how to make the thing with the correct answer. What I think is that I need to random integer and then check what of these cubes has the name of that number

UPD: I checked your last screenshot and see that there’s random array for this. So do I name the cubes like “1“, “2“, etc?

UPD2: I tested this out and because the color is chosen in the construction script, they don’t change when I start the game. Is making this with begin play a better option?

I have a question. Firstly, not so important but how do I make the connections of the nodes like you have?

It’s a plugin called electric nodes.

Secondly, I’m not really sure how to make the thing with the correct answer. What I think is that I need to random integer and then check what of these cubes has the name of that number

Sure you can assign index for each actor instance in the level like below

UPD: I checked your last screenshot and see that there’s random array for this. So do I name the cubes like “1“, “2“, etc?

No you dont have to, since they are actor if you copy paste them in the level they will name themselves automatically. In this screen shot I am basically showing you on UI or in another scripts how to access your cubes in the level.

Since all of our cubes in the level actor :

We can get all of them access their specific colors and know what colors are in the level assigned to cubes. So AllColors is a new array that we iterate through them and add them to an array.

Now you can assign one correct color in your UI from that array to solve the puzzle. Or whatever design you have, I am just assuming what you are doing and showing you the knobs.

UPD2: I tested this out and because the color is chosen in the construction script, they don’t change when I start the game. Is making this with begin play a better option?

Not much of a difference if your system requires you can do like that.

Here is with the begin play

Additionally I created a widget for your boxes and assigned some not correct and one correct color (that exist in level)

– Results

Let me know if things unclear. however rather than doing all together I suggest going step by step replicating and overcoming obstacles.

Thank you so much. How do I make buttons work. I need to call event dispatcher when I press the button. But how do I “link“ it by knowing only the variable?

I’ll mark this question as solved for now. Thanks for helping me!

You can just assign 4 buttons, inside button put images.

There is an event OnButtonClicked you can have that and check if player’s clicked button index matches the correct color index.

No worries, happy developing.

1 Like