Cast succeed on one level, fail on another

I’m confused.
Lately I’ve been trying to create a system for lighting.
I wanted each spotlight to be controlled by a switch, a breaker, a main breaker, and a control panel.
At first it went successfull, and it still kinda does. I made a level just to experiment with that, and there it works completely fine, but once I open the actual game level, it doesn’t work. It’s the same blueprints and all, but the light never toggles.

This picture above is the lighting. Each and every light source will have this pasted into the event graph. This casts to a variable that checks an assigned object in the level. I will get deeper into that. But this lets me chose which switches and breakers control what lights. If the cast fails, it jumps over to the next cast, leaving me with the posibility to leave out a breaker if I desire to do so.

Here is an example, including the variables. Again, each variable holds an assigned switch or breaker in the level.

232094-ue42.png

Here is how each light appear in the editor. Each light can have separate objects selected. Now, the blueprints are set up in a way that can only hold four objects, and each variable has to be the specific kind. The switch variable only accepts switch blueprints, the sub breaker only accept sub breaker blueprints, but they all work the same, except the name of the bool that decides if the switch is on or off.

This is inside the switch blueprint. Very simple, but it works.
I know that the entire setup is a bit weird, but I’m experimenting a bit. Still, it works completely fine in the Test level, but in the actual game level it don’t, even with the same blueprints
I have simulated the lighting, and it appears that it isn’t getting any info. The cast always fails, and jumps to the next execution node.

Sorry for the long post, but I wanted to be as clear as possible. If anyone have any idea what the problem might be, I would love to hear from you.

I have a couple of questions to clarify what it is your trying to accomplish. My understanding is that you want to be able to turn off the light by any of the assigned switch, breakers, sub-breakers, etc… First what is the hierarchy relationships between switches and breakers? Are they derived from a single base class?

Second why are you casting to the type your specifically defined for each slot? Is there a programmatic reason for this versus an IsValid check?

Well, the point is to kind of simulate how an actual electrical system would work. Every single switch or breaker has to be turned on for the light to be on. If any of those break the “circuit”, then it turns off. The lighting blueprint check every tick if any of the variables are set to false. Every blueprint is just based on an actor blueprint. I created an actor blueprint, made the variables. Then I copied all the functions, but left the variables. Then I would create a new actor blueprint, paste in the functions, but create new variables. Now I could just drag the breakers out into the level, and assign which light they were supposed to affect. So, all of the blueprints used are based on the completely basic actor blueprint.

I did it this way, simply because I didn’t know about any other way. I’m fairly new to this. Have tried to communicate between blueprints before but found it difficult. A few days ago I suddenly understood casting and have been using that.

Ok. First thing that jumps out it derive child blueprints from a base actor blueprint… This eliminates the copy/paste operations… And copy/paste doesn’t always work as expected when it comes to seperate blueprints.

Your switch and breakers need to derive from the same base class also. You can still specialize the four entries on your light actors but you don’t need casts because the IsOn function is part of the base blueprint. Such as create a switch blueprint that implements your boolean for on/off state. The create child blueprints from that switch blueprint for each breaker type. Because they are all based off of switch, you can just do a validity check and use the boolean as needed.

This structured hierarchy will make debugging easier and overall the code will be less prone to errors as well.

Yeah, I’ve discovered a few different ways of achieving the same result along the way, but don’t want to start all over. The thing is, it worked perfectly. That’s why I’m here, there weren’t any problems to begin with, but placing the actors in a new level suddenly didn’t work.

But wouldn’t I need a cast from the light to any of the switches anyways? There needs to be some kind of blueprint communication, right? I think I need to look into validity checks, haven’t used that before.

Hmmm. Yeah, I get that there are loads of better ways to do it. But still, I find it so confusing and want to figure out the actual problem. Just for the sake of learning.

So, after messing around a little I have found some new stuff that are worth mentioning.
What I did at first was to make a class, for example SwitchBP, and then copy this into another folder, and then customize it. This way I could make several different switches with different design.

Something I found though, was that everything used in the new level, IF, I used the original blueprints. As in, the original, unmodified SwitchBP. Once I pasted this into another folder content browser, and then used the new switch, it wouldn’t work. Interesting stuff. It doesn’t seem like it needs to be in the same folder, and that wouldn’t make any sense.

Also, a new light will react to the original switches. It’s just when I create a new switch. I don’t know what is happening with the failed cast, why a duplicate of the original blueprint doesn’t work. I can have as many as I want in the level, that doesn’t change anything. But a duplicate in the content browser? Weird stuff.

Its a long time ago, but I’ve figured it out. You were right, the system I had was awful. Now all the receivers derive from the same parent blueprint, and instead of a long line of casting, I’m just adding all the actors in the scene that should communicate in an array, and then use a foreachloopwithbreak to check if all of them have the bool “on”.