Download

Multiple light drain

Hi,

I have 4 lights, and a progress bar on my HUD. The lights can be turned on individually. I need to write a blueprint so that depending how many lights are turned on, the battery drains more or less.

Thanks!

Call LightSwitch when a light comes on / off.

Could be improved, you could pause timer execution when no lights are on. I’ve assumed each light draws the same about of power.


There are other ways of keeping track of it - an array, or query lights’ status but the above should be more efficient.

Thank you very much! I will try it out and let you know. Is this done in the level blueprint?

No, an actor. This can be anywhere, you could even place this in the widget itself.

So should I copy paste this to each light switch blueprint? Or do I only need to do it to one of them?

I wouldn’t put it there - it should be somewhere outside the light switch actor. There is no need for the light switches to know about each other and no need to duplicate the script.

If the Battery is an actor, it could go there. Not sure what your setup is, hard to advise. The Player blueprint makes sense in most cases, but you may not have a player. Who knows.

Perhaps you could explain briefly what the overall structure of the game is. Is it a car that has 4 lights? A puzzle room that has 4 lights?

The battery is just shown on the player HUD.
It’s a first person player in a car with 4 lights (1 for each seat of the car).
I have set the player input to turn each light on depending what seat he is in in the car. (Each seperate light has the script with the players input button)
The movement to each seat of the car script is placed in the level blueprint.
The HUD is set in the level blueprint

If the battery and lights belong / are a part of the car, I’d create the widget in the car and do the calculations there as well. All of that goes into the car, only once. Avoid scripting in the Level Blueprint if you can.

Good idea. The lights are a part of the car however they are not linked to the car. How would I go about doing that?

If the lights are components, they can be added directly.


If you turned the lights into full actors (you may have your reasons - method of interaction, perhaps), you can add them via a Child Actor Component:

Each of those components will automatically create and maintain the life cycle of the instance of the Child Actor Class. The car can then access the lights via a cast, as above. The CACs can be placed around the car, as needed or even attached to sockets:

The lights can reach out to the car like so:

Edit: but at this point I’d have the lights talk to the car via dispatcher delegates, much cleaner and all can be contained in the car.

Thank you very much. I will try this out. How do I actually check to see if something is an actor or component though?

image

vs

image

Oh I see, thanks. Wouldn’t all lights be actors then?

No.

image

This is an actor with 4 light components. But nothing stops you (performance does) from creating an actor with a single light component.

I see… when would a light as an component be more useful? Since I want to be able to switch lights on and off depending what seat I am in, should I just make them seperate?

I do have a major issue however… I start in the car but light switch does not work because the triggervolume(box) is what my player starts in. Is there a way I can start the game and use the light switch without the need of trigger box?

Depends. If you’re planning to have some complex behaviours for the light, you may want to have it as a separate actor and attach it via the Child Actor Component. If the behaviours are simple or you’re after simplicity of communication in general, this might be enough:

image

Again, it really depends on the requirements. You can see some repetitive pattern above. Perhaps the CarSeat should be an actor and have a light component. So you can script the logic in the CarSeat and add those actors to the car.

Yes. At any time you can:

image

To see what is around the actor that is calling this.

Where abouts would I place that bluescript? in the light?
I think what would be best for me is to have the player able to switch lights (depending on the seat he is in) and only by looking at the light switch. Everywhere I see it says I need trigger boxes to do that, but I am starting the game in the car so I can’t use a trigger box (however I do need a trigger box to help find which seat the player is sitting in).
I have a small dot crosshair in the middle of the screen, so when the crosshair is over the light switch I am only then able to use the switch. But not able to use that switch if in any other seat of the car.
I have searched for days but can’t find a way to do this

Only way seems to be begin overlap boxes, but if I start in that box I cant do that…