Creating array of Point Light Components within a BluePrint (and possible bug)

I have a base blueprint which will be used to create several others that will all share some specific functionality. One such function is that a number of lights will light up depending on a changing integer value on each instance of the object. Each instance will have a different number of lights, so I can’t just hard code it.

My attempt to do this was to use an array of Point Light Component References. However, you can’t set the default entries on such an array with existing PLCs in the current BP scene, which seems odd. I tackled this by having the construction event add each light one at a time to the array, which is obviously a fudgy solution.

PLC Lights in the BP scene and not showing in array add interface


The workaround

I have two things, one question and one possible bug:

Q: How can I have a predefined array on a BP that I can set each element to an existing Point Light Component in the BP scene - OR - a way to achieve the same goal in an automated/expandable way (not manually add them).

BUG: When I run my game in the editor, I’m seeing a random number of either “Nothing” entries getting added to the PLC array, or sometimes items called “TRASH…(I can’t make it do it right now and can’t remember the rest of the line)”. I can remove them at runtime to prevent issues, or clear them between runs with the “Trash” icon on the array, but they’ll come back when I stop and run again (but not always, often depends if I edit the blueprints or some such).

Array when its behaving

Array when random “None” entries show up

Hard to understand for me what you’re trying to do exactly… You just want to add a certain number of point lights to a BP quickly & easily? Is the only issue here adding them manually (and the bug, which I can’t comment on)

What is the BP meant to do exactly?

I want to create blueprints based on this base blueprint, each of which will have a number of lights, that based on a calculation that results in a %, will either be on or off.

So say the result is 50% and there are four lights in the array, lights 1 and 2 will turn on (based on a foreach loops over the array). If there are 10 lights in the array, 1,2,3,4 and 5 will turn on.

I don’t want to make logic for each possible number of lights, nor do I want to manually insert each light in to the array for each instance of the BP (the workaround I did). I want to be able to create a new BP based on the base BP, add a number of lights, set them in the array as default elements in the editor and be done.

I’m happy if there is another way to achieve that result by other equally simple means.

Sounds like you have everything else handled, except for the amount of lights. I’ll post an answer on how to add them easily. Also with some simple positioning functionality. Not sure how you wanted it, I assume you have it covered.

Here’s how to add lights dynamically using only a variable + construction script.

Here it is in action

That is pretty nice, I may well use that for something else - though it doesn’t actually tackle the issue I have, as the lights are manually placed on the model and may be placed in non-linear positions (perhaps a circle on one, a line or arc on another). I was aware that dynamically creating the lights was a solution, though I hadn’t planned to make it as dynamic as your BP allows - I already have a bunch of ideas I could use that for now I’ve seen it :slight_smile:

Oh, so the problem is adding them into an array, not into the BP itself. Sorry, should have noticed you specifically said array. Was up super late :slight_smile:

Would this work for you, then?

I did the forloop because directly connecting the output was giving me an extra billboard component.

While I get the point of what you’ve suggested, there’s no telling how it may order the children it iterates over, and in the end its using a foreach to effectively do the same thing as my manual code does - I suspect it will fall foul of the same random extra entries issue - but I’ll try it all the same (I did thinking of doing this, but assumed it wouldn’t help so didn’t).

Forgot to come back on here :slight_smile: Using a loop to achieve the same thing had the same issue. However, the fix was that the target array needed to be cleared first - I assumed it’d be cleared before each “construction” event, but apparently not, at least not properly. I guess that’s why some items ended up being called “TRASH” or other random junk.