Need Help With Boolean System.

I have a selection preview setup. You can also click one of the selections to delete it. But im having trouble when deleting a selection undoing the boolean that says that selection is in use. I have a different boolean for each selection 7 in total. How can i specify which of the 7 selections has been undone? And after the actor is spawned into the preview it changes the boolean for that location to in use.

Would an array of booleans be better here? That way each selection object/widget/whateve you’re using can store a reference to it’s own index in that array, so you know which one to set true/false when in use or not.

You can also just use a foreach loop instead of all those ‘if’ nodes to do that test above.

Yep. Arrays and loops are your best friends when you start coding more complicated systems. I suggest you learn and impelent them early.

Also, flow control. You should look at “Sequence” and “Select” in particular.

I have this first image setup to spawn the object at the first location if it is not in use. And then it uses an event disbatcher to check if thats the one that was supposed to be spawned if not it will destroy the actor and supposed to set the location as not used. But im having trouble trying to do this. With only the slot for the actor that was destroyed. How will arrays help it? All i see they do is store the bool.



Ive looked into arrays and all i can see is it just cleans up the mess of the bp a bit.

It’s a good idea to start becoming used to thinking in terms of for/for each loops though, you’ll very quickly start doing things where there are really no other solutions. Iterating over a list of ‘things’ is a staple of a lot of programming and very useful.

With an array you get an index though, which you can store and refer to later to know which slot was in use. For example when you spawn that ‘eyes’ actor, you could have a variable on that actor that holds the index of the slot it’s being placed in. When you destroy that actor later, you can ask it what slot it belongs to, and then set that value in the array to false.

Can you give me an example of it? Or do you know of any documentation i can look at. Sorry im not near a computer atm.

Ok ive setup arrays instead of branches but this does not fix the problem im trying to solve.

Sorry, I forgot to respond to this last night! When I get home tonight ill see if I can do a mock-up of what I meant and see if it makes it any clearer.

Ok, Thanks

Ok so what it sounds like you’re trying to do is have a bunch of objects you can spawn and assign to ‘slots’, which then get set to ‘used’ and cant be occupied by another item. When you delete that item, you want to go back and make that slot free for use again, is that right?

Here’s how I’d go about something like that using the setup you have so far.

To start with, in your ‘Eyes’ blueprint (and in the blueprint of any actor you intend to occupy a slot in this way) i would put an integer variable to store the index of the slot that this object ends up getting placed in. I just called it ‘SlotIndex’ in the pic below. I also checked the boxes “editable” and “expose on spawn” so that we can play with it when we spawn the actor.


Then, In whatever blueprint you’re doing that slot management, I would make an array of booleans (i just called mine “Slots”), which can store any number of slots for you, and will tell you whether the slot is occupied (true) or empty (false).
In the begin play event, or whatever event fires before doing any of the spawning, you can set the size of the array to whatever you like. You wanted 7 slots, so that’s what I’ve done here. You don’t really have to resize this in advance if you don’t want, as you can just keep adding slots dynamically, but in this case, i put in check to make sure we can’t go over the set number of slots, so you can limit it to the number you want.


The next part would be the main section, where you are spawning the Eyes actor:

So what this event is doing:

1 - Check that whatever index we want to put the eyes in is actually within the size of the slot array. So you can put it in slot 0, slot 1, etc, but not say slot 8 as I only made 7 slots in the begin play event.
2 - The next branch is the same thing as what you had when you were checking the “In Use 1?” bool in your last post. It’s just checking that the slot we want to put the eyes in is not already being used.
3 - Spawn the eyes, and tell it what it’s index is (give it the slot variable).
4 - Set that particular slot to true in our array using Set Array Elem. Important to note here that i left ‘Size to fit’ unchecked, so that if the index is larger than the number of slots we initially set, the array won’t just automatically resize itself (which it would do if we had that option ticked). This shouldn’t happen anyway because I tested to make sure the index was within range but just to be safe :slight_smile:

Once you’ve done that, the Eyes actor now ‘knows’ what slot it belongs to. When you want to delete it, you can do something like this:


So this is deleting the eyes actor. Before it does that though, it tells the array to set the previously occupied slot to unoccupied, then destroys the actor. Since we previously told the eyes what slot it belongs to, all we have to do is get that variable from the eyes actor and it will match the correct index in our array.

Hopefully that helps! Sorry if that’s a tad too thorough, obviously you how how to make variables and that sort of thing! :stuck_out_tongue: but that should give you an overview of how i’d put the process in from start to finish.

You could even make this more generic. You don’t actually have to specify what slot you want the eyes in if you don’t want to, you could write a functioned called 'Find free slot" or whatever, that loops through your boolean array and looks for the first free slot (first false). When it finds it, it returns that index, or returns a fail (i usually use -1) if it couldn’t find a free slot. You can then use that slot to spawn whatever actor, and as long as you tell that actor what slot it belongs to, you’ll always know which one to free up when you remove that actor.

I hope this is what you’re trying to do otherwise I’ve completely misunderstood your original question :stuck_out_tongue:

Thanks you understood the question. But im trying to do what you said at the end ill just have it find a free slot not specify what one each object uses. So when i get home ill have get that working. Also, Since i have 7 different locations the objects spawn will i have to use this for each location. (Target1 is just the first place something can spawn). How i have it now i have to do this same setup 7 times to get the objects to spawn in any of the slots. But it kind of seems to me that your setup has the ability to scan ones that are empty and select one? Let me know if im wrong :P. I know im trying to tackle a big system while still trying to learn more.

The Slots are the locations of these collisions i have in a BP.

Yeah you should be able to set it up to search for and find an empty slot, no matter how many you have. You could do it in a number of different ways, but one way to do it would be, if those 7 slots are all in the same blueprint, make an array with them (use the MakeArray node in the begin play or something in that blueprint, and plug all of those locations in). Then you would have an array of booleans telling you which slots are free, and the array of slots themselves where you can spawn things. The index you use to test whether something is occupied/free will be the same one you use to select which of those 7 spots to spawn something.

This way you should be able to easily increase/decrease the number of slots too, just by changing the size of the bool array and the location array. I do something similar with my inventory system, as i have a number of on-screen slots which match up to an array of inventory items on the player, and i need to be able to test which slots are free so i can add more items when the player picks them up.

Arrays are pretty great :slight_smile:

Speaking of inventory, if you’re feeling like delving deeper, take a look at . It’s the tutorial stream Epic have set up for creating a drag-and-drop inventory system. Its quite long and involved, but they use the same method with array’s that we’re using to make sure that the on-screen-slots match up to a player’s inventory somewhere. But what we’ve talked about already should get your particular implementation sorted :slight_smile:

Ok, thanks for that video ill have to watch it when i setup drag and drop system. Also what do you mean in your post about about the find free slot function. I made the array loop with a forloop and the bool array then a return vaule with the bool array index. But Does this connect to the setup from earlier and also what do i replace the “Slot for eye” variable with since im not selecting a certain slot. Sorry this is getting a bit confusing.

The find free slot function would be something you just write yourself, just a helper function that looks through the boolean array for the first free slot (first false entry) and returns the index of that spot. Something like this:

This function just sets a temporary index (local variable) to -1 (you can set it to whatever to begin with - just make sure it’s something outside of the index range of your slot array). It then loops through your slots and checks whether they are true (occupied) or false (free). As soon as it finds a free one, it sets the index to the index of the array at that point, and then breaks out of the loop. Then it returns whatever index it found. If the loop finishes without ever finding a free slot, then the index will still be the originally set value of -1.

You’d then modify your spawn event to something like the below:

Now all you need to do is call the find free slot function, and it will give you the index of the first free slot, which you can assign to some variable. I’m then testing that variable to see if it’s -1 (which it will be from before if there’s no free slots). If it’s not -1, then we’ve got a valid index, and we can go ahead and do the spawning like before using this new slot.

Ok, That works way better then my setup did :P. Now im having trouble with them all spawning on target 1. I put all locations into a “Make Array” Node and then plugged that into a “get” node and plugged that into get actor transform. Did i mess it up somewhere or am i doing something wrong?.

Hm that sounds like it should work, do you have a screen of how you’re setting that up? You’re plugging the spawn slot into that get node to get the correct slot after calling the find free slot function yeah?

Ok yeah i just had typed the number of slots into the get but attaching the spawn slot into it worked. But now there is one last thing. Destroying is giving me a few problems now. 1st: it only destroys the last one that was spawned and nothing before or after that. also its giving me this error ill post a picture of. And finally if i spawn a few of one object then i spawn something different it skips a slot.

We’d probably need to see some shots of the spawn/destroy events to find out whats going on there i’d say.