Why it's doesn't work?

Hi! I remember your project from your previous posts.

I’m not entirely sure what the problem is this time, but I noticed a few things that look wrong:

First, you don’t need to create a new Dynamic Material Instance every few ticks. Set it up once, either in the Construction Script or on Begin Play in the EventGraph. Then save the Return Value in a Material Instance
variable
. (You’ll need this variable to compare your colors.)

56873-dynamicmaterial_variable.png

Second, don’t use a Delay in the EventTick. Instead, create a new function that does what your event currently does. In reaction to the Begin Play event, set up a looping Set Timer node to trigger the function. (Your function probably works, but it’s much more expensive than it needs to be.)

56874-loopingtimer.png

The looping timer does the same as the Tick delay (but a bit cleaner). I’ve changed some details in the function but it’s still basically the same Blueprint logic. The biggest difference is that I no longer create a new Dynamic Material Instance every tick. Instead, I only change the Dynamic Material variable I created earlier.

Last and most importantly, in your CompareColor function, the Orange color is currently always compared against the same color (the first in the array). Instead you need to get the material’s current color and compare against that.

I don’t know what the Color_Sun macro does, so I was unable to test this. But at least you’re now comparing against the actor’s actual color. Also, I included a check whether the Get All Actors Of Class returns a non-empty array before trying to get its first entry. Accessing an array element with an invalid index is a common source of problems (“array out of bounds”), so comparing the index with the array length is generally good practise when programming.

I hope this helps you along. Good luck!