Download

Basic Lightswitch Problem

Hello everyone,

I am having an issue creating a blueprint for a lightswitch to do a basic task of turning lights on and off when you press your use key and the thing is… It doesn’t work and I don’t know what I’ve done wrong or if I have forgotten to do anything.

I have attached some photos of all my blueprints that are being used in conjunction with the lightswitch blueprint.

336e0945e2ed9e9c60c39d950a115a0ab0b43a7d.jpeg

a1bb5b016f610ac4e2314b2082ac88f5d17d29ac.jpeg 90a5d1f5ae91b249353427114a38ef72586c740d.jpeg

Can somebody point out my mistake and tell me how fix it? I am relatively new to blueprint scripting,
Goolog

Are you sure that the BluePrint is receiving the input key? Try use a “print string” just after events start (i mean, just after “interact” with them). If there is no text, it will mean that events never happen.

After you check it, the next step is check if it do something, whatever.

If you press Play and keep an eye in the code of your Blueprints, you can select a “Debug Filter” and see the how game is moving along all nodes. With that you can see if it enter in the code that Should enter.

The Cast To node in the lightswitch blueprint is what’s not working… I’ve tried a few methods and they don’t appear to work. I do not know what the object reference in the node means. Meanwhile I get a compile warning saying that ‘BP Ceiling Light’ does not inherit from ‘Static Mesh Component’ (Cast To BP_CeilingLight would always fail). When a blueprint doesn’t inherit from something, I don’t know what it means.

Maybe you should start doing it step by step and keep if what you do work or not.

I mean, first try that a string happen in screen when you interact. When you do it, then next step should be switch on a single light, after switch on and off, later more lights, etc etc. I guess you get the point.

I am very novice too, so I could be wrong. Anyway I’ll say you what I see and what I try. Lets checks the pictures:

in your “BP_Lights switch” blueprint you have a component (called “var lightswitch”, and if I am not wrong you created it dragging it from scene components to blueprint). It is ok, but in order to interact with a blueprint it’s object must be declarated as that blueprint (I mean, if you want interact with the blueprint called “BP_Ceilling Light” you must create a variable declared as “BP_Ceilling Light” type).

In your “BP_ceilling light” blueprint you have a boolean variable that never change in code (and if I am not wrong, it should be set ON and OFF after the branch).

In your last image, “Player control”, I guess you tryed it already and saw it work. I really try and check this first, just change that “on interact” to a “print string” and see if you see the text.

This isn’t really a fix to your problem, but try this out in your construction script:

I copied this out but some of the blueprint is still offscreen in the screenshot. Can you send me another plz?

Actually, I tried it out, it adds point lights to the lightswitch itself then you gotta adjust the XYZ vectors to fit the exact location of the Ceiling Light itself… I want the lightswitch to be able to control the visibility of the pointlight that is located within the ceiling light blueprint.

This is a very simple setup for toggling a light on and off on a key press when inside a trigger box. You should be able to modify it to work from a line trace. This setup uses blueprint interfaces which I assume you understand along with how to correctly reference actors in the scene.

Switch Blueprint:
UE4_LightSwitch_01.png

Light Blueprint:
689f428372b1eeb53dbe4bdb1dee071f41ae66f2.png

Like I said, not a fix to your problem, but it is still pretty cool. If you check the show 3d widget on your transform array variable, you can drag the point lights around as if it was actually there.
It lets you re use your light switch blueprint and not make a new bp to have more lights, or from having to get references to lights.