This is for game logic. I have a number Switch Actors instanced in my level. Each switch can be off or on. I am trying to create an array of the switch instances with the correct state that solves the puzzle. Made a blueprint struct called SwitchKey that has two members: a reference to a Switch Actor, and a bool for the correct state.
Want to have a predefined array of these structs in the level or game blueprint that I can check against so when all the switches are set to the correct state the puzzle is solved. I figured a for each loop over the struct of SwitchKey, get the actor ref, compare the state, etc…
The problem is even though I can create an array of SwitchKey structs and add the needed number of elements I cannot set the default switch actor references to point the the switches in the level. Tried soft references in the struct but I still cannot set the values. How do I connect to the switch actors from the level to the array of structs before runtime?
I hear what you mean, but they do exist in the level editor. There is no way to grab a hold of those?
Using names as a shared key identifier is a good approach though I wanted direct access to the actor object without having to do a lookup. Tags not so much because I would like to decouple the puzzle logic from the switch itself. That way the solution could change depending on other things, not be hardwired to the instance.
if im understanding you correctly your just looking to have a situation where you have a actor that has a reference to each switch in your level (the ones that apply to the puzzle), and you want the actor to have what the switch state should be for the puzzle to be correct. if thats the case then the solution is pretty simple you just need to create a variable array of the type of your struct, then make the variable public (click the eye). this will allow you to edit the variable from the level editor and you can set references to the actors in the level. i made a little example below.
in the first picture you will see my door bp which is what the puzzle will be solving (get all the switches right and the door opens). first i made the struct which was two variables: switch actor reference and bool. then in the door bp i created a variable switchesInfo, made it array and public, and set its type to the struct (switchCheck). then i made a little script which checks the state of each switch and compares it to the correct state, if any dont match the correct state then the gate closes.
the second picture shows the details panel of the level editor with the door bp selected. here you can see the switches info variable we created and this is where you can populate the array. as you can see i created a index for each switch actor in my level and the index contains a reference to the switch and what the state should be. if you want to add another switch you just add another index.
the main idea here is that with a public variable you can easily reference actors in the level. i just noticed this is basically what is suggested in another post but o well.
Interesting using an actor as a controller object… I found another solution, via looking at sets as you said, which lead to maps, which lead to solution I am posting below.
So instead of using an array I used a map. The keys are soft references set to the SwitchActor instances in the level, the values are booleans set to the solution state. It works!
That is exactly what I tried to do! I wonder why I couldn’t set the actors in the array of structs… I think I set the array to public, maybe I forgot to recompile. Going to try again this way to see if I can get it to work. I like the sequence into gate setup.
I see what I was doing wrong with this approach. I was going to the “Class Default Object” when I was trying to set the values in the array of struct. Finally I went to the Details -of the control actor dropped in the level- and there I could set the references! Thanks for the help!