Why it's doesn't work?
hi, i made color compare color macro and blueprint which is comparing colors of one actor and other ones which colors are diferrent. I've created dynamic material for one actor but it doesnt work. there arent any comapring with these objects. Ps. In the other actors are blueprints alluding to gamemode blueprint.
asked Sep 02 '15 at 02:28 PM in Blueprint Scripting
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.)
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.)
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!
answered Sep 02 '15 at 07:42 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here