Predefine array of struct with actor members
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?
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.
answered Jan 23 '19 at 11:10 PM
AFAIK you cannot get a reference to an actor before runtime (because it doesnt exist yet).
Maybe you should give them names/ids/tags on which you perform the switch. Try holding the correct states in a set with the names/ids/tags as keys.
Follow this question
Once you sign in you will be able to subscribe for any updates here