Is this the best way to do this ? Retrieving what color/type of the actor I am entering.

Hello all.

I decided create, to the best of my abilities, a duplicate of the Donkey Kong 64 Factory Boss. Looks something like this

Breaking the game down, I decided to create a C++ Actor for the Blue and White pads called Pad.cpp, these pads will tell the AI where I am currently at (also where to create the button to electrocute the boss). Then, I created a derived Blueprint from that actor. Inside the blueprint, I made a long cube and added the collision for the overlap event and so on.

I created two white and blue materials for each of these pads.

In the C++ actor, I code in all the meshes, root component and so on.

The AI and “button press” needs to know what color pad I am currently in. So, what is the best way to do that ? Retrieve the material name and check if it’s “white” or “blue” ? Perhaps I could retrieve the ID and not really worry about the color. I thought maybe I could create two derived blueprints from the base C++ Actor Class but I think that that will be too tedious, surely there is a better way.

Code so far for the Pad.cpp

Screenshot of what I made so far.

Thank you for the help!

Hey HappyZombies-

If you are just trying to determine “is this cube white or blue?”, one simple solution would be to add an bIsCubeWhite boolean variable to your actor class. All instances that are white will have this set to true and instances that are blue would be false. You can then check the value of the boolean to tell what color cube you’re on.

Cheers

I think this solution works out , thanks! Now, I imagine this bIsCubeWhite boolean variable should be available via the editor with UPROPERTY correct ?

Also…say I want to extend this forward, say I have 4 colors instead. Would it be better to perhaps have a UPROPERTY of FColor ? I can’t use boolean in this case. Thanks again!

Correct, marking the boolean as UPROPERTY would allow you to set it inside the editor. As for your second question, it would depend on how you’re defining your colors. Since each element of the R,G,B that makes up the FColor can range from 0-255, if you are not using one of the defined FColors (found in Color.cpp) you would have to check each element independently to ensure you are specifying the intended color. If you are using the colors listed in Color.cpp, you can check your FColor variable against that specific color. For example, if(MyColor == FColor::Blue) would return true if you set MyColor equal to FColor::Blue in code or (0,0,255) in the editor. However (0,0,254) would return false since it is not the exact same as FColor::Blue.