Set Light Color in Actor from Array

I’m trying to set the color of a point light in an actor from an array of colors. My reason is that many objects will use this list of colors, so if I wanted to change them in the future, I don’t want to be forced to change every object. I’m just starting to learn Blueprint, so I have no idea what I’m doing. From looking online, this is as far as I’ve gotten. I think it should work, but the light’s color hasn’t been changed by my code. Can someone help me? I’m sure that this is very basic stuff. Thanks.

If its the same object u place everytime (or blueprint actor) just, rightclick on the set light color on the newlight color pin and promote it to a variable. and thats basically it. Just the construct script node. the set light color and the variable. You can change the light color then in the variables tab on the left. But then u have to open the actor blueprint and change the color there

No, this is in the actor blueprint. The light is inside the actor and I have many objects like this. I’m trying to have the color of the light in the actor be set by a shared array variable. I need to import that array into every object that has a light, which will be a lot. I thought I’d use the Construction Script part of the actors, unless that is wrong. Are you suggesting that I do the code from outside each actor?

Assuming you are not changing the array order?

Create an “enum” called “ColourList” , add a list of colours you want, starting with an unused option, reason will become obvious later.
Create a structure called “LightMap” , inside the structure add a new variable of type “ColourList” make it a map, second side of map select “LinearColor” .
Add elements for all the colour options, the unused name being the default that you have to change from, you will understand.

This structure you can add as a variable within your object blueprint, or the blueprint deciding on colour, now you have unlimited options and an easily selected dropdown list of colours,
also when placing the struct in a graph you can right click and split pin, pull out a find, and on the right side promote the enum input to a variable, you could expose this variable on spawn if you are spawning from another action or blueprint, or from the struct use “keys” with a get followed by a find to only require a single integer to be feed into your function. either way you don’t have to remember or hunt for colour numbers, just select from a list :slight_smile:

Just realized, for seeing correct colour during level building, yes place in construction.
But if it is running off another blueprint, like changing colour when hit then events graph or functions as per normal.
Think of construction as just that, initial build of object before using.

From what I’ve seen, my method should work. It even compiles without errors. I don’t know. Maybe my editor is broken. I’ll be reinstalling soon, so I’ll find out then. Thanks for any help, folks.

UPDATE: The failure is in casting from inside the actor since I can do the same code with an array inside the actor. My problem is in trying to bring in a reference to an array that is outside the actor.

UPDATE 2: From what I’m reading, doing this to save me time would break my game in many cases, making this ridiculous. I’ll just go through the trouble of changing the colors manually. I just don’t understand why the Material Parameter Collection makes the changing of all of the emissive colors so easy while changing light colors is so hard.

If you want to continue with the game instance array you currently have…a few things to take into consideration:

  1. Your picture suggests you have a game instance called “Variables” , bad idea using a common name, better to use a unique name for blueprints.

**Also for this to work, “Variables” should be set as the designated level game instance. “Game_Instance” is a special blueprint not sure of your knowledge level, no insult intended. (only one game instance runs per level, sure you can cast to game instance that is not running without a compile error, but they are dead) Suspect this is the case.

Run a print string off the cast fails pin to check… **

  1. Casting to game instance from construction could result in timing errors not sure on this but doesn’t hurt to error check, run a print string off the failed cast pin to check if cast still fails, then try using begin play instead to ensure game instance is present, but then light settings will only show in the running game and not in level designing.

  2. If you have created an array in a blueprint like in “Variables game instance”, you either have to feed variables into it or manually set the array elements and their variables, check if the array elements have the correct colour settings, be annoying if they are set to default.

“Variables” is a game instance. I’m not going to use an array for colors and will set the color of each light individually. I’ve decided to make a rule for myself that all blueprint code should relate to gameplay to prevent any unexpected bugs later on. Thank you for the help.