x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.20
Tags:
more ▼

asked Jan 23 '19 at 09:24 PM in Blueprint Scripting

avatar image

rebusb
10 1 3 8

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

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.

alt text

alt text

capture.png (279.2 kB)
capture1.png (34.6 kB)
more ▼

answered Jan 23 '19 at 11:10 PM

avatar image

ThompsonN13
9.1k 31 8 20

avatar image rebusb Jan 23 '19 at 11:25 PM

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.

avatar image rebusb Jan 23 '19 at 11:40 PM

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!

avatar image ThompsonN13 Jan 23 '19 at 11:44 PM

ah yup thatd do it, pretty common mistake. glad you got it working.

avatar image rebusb Jan 23 '19 at 11:52 PM

Hmm... not sure who I should give the check mark to... this answers the question but I came up with a way that doesn't need the additional actor and puts the logic in the level blueprint. Well my way takes it in another direction so ...

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Jan 23 '19 at 09:44 PM

avatar image

procrastech
56 2 2

avatar image rebusb Jan 23 '19 at 09:56 PM

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.

Unless I am looking at tags wrong...

avatar image procrastech Jan 23 '19 at 10:27 PM

Okay, i learned something today :) Only spawned Actors can have a reference to other Spawned Scene Actors.

Using an Actor as Holder for these references works. Mind that the ref for the switch in the struct has to be of type actor ref apparently.

Edit: Holding the refs in the Level BP works too.

alt text

alt text

10.jpg (300.6 kB)
11.jpg (56.1 kB)
avatar image rebusb Jan 23 '19 at 11:04 PM

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.

avatar image procrastech Jan 24 '19 at 12:14 AM

Ugh, i meant maps! Obviously maps have keys, not sets. Sry for the confusion.

(comments are locked)
10|2000 characters needed characters left

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!

alt text

more ▼

answered Jan 23 '19 at 11:19 PM

avatar image

rebusb
10 1 3 8

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question