Item spawn array help

I have an event in the level BP that spawns a item in one of X preset locations (SpawnLocations). From BeginPlay, a CustomEvent gets all actors from the SpawnLocations and spawns a BOX in one of them.

From lvl_BP

There is an interaction with the BP_Box that allows me to destroy it and have a dispatch that lets the level know to do it again.

From BP_Box:

From lvl_BP:

All of this works properly, however I am trying to make sure it doesn’t spawn in the same place twice in a row. It can spawn multiple times but I do not want it to do it back-to-back. Any help or ideas how to do this would be great

Create an array of the item spawn locations, whe one is selected to have an item spawned, add that to the array. Then in the event for selecting a new location, query that array for the selected location, if it is there, select a new location. Alternately, you could preload the array with all the locations, select random every time an item is spawned, and remove that index.

How could I create an array that stores them? I am still pretty new at this and am self teaching / VOD taught game dev, so sorry for what might be basic questions.

The dispatcher event can pass a reference to exclude. That’s the easiest and most performant route.

Sorry to bother you about this, but how would I do that? This is my frist time trying dispatchers.

You’d set a variable in the BP. Or better yet, if this level will be persistent throughout play, you could just destroy the box spawn location actor after spawning the box in its location. That would probably be the best way performance/memory wise to accomplish this. This way when you call “get all actors" it won’t be found. Thus removing the need for an array and other query functionality.

Update: it looks like your already doing this but then respawning an actor? Why not just leave it destroyed? That would fix your issue.

Question: are these “locations” preset variables in the level BP? Or actors in the world you have placed? Just wanting to make sure I understand exactly what’s being done here.

I want the ability to spawn it in that location again, just not twice in a row. However, now that I am thinking about it, I like your way. I might try that

the Spawn Locations are actors I am have placed

Got it so what you could do is set a variable in the level BP of a reference to that actor object type. Every time a location is selected, set that variable to it. On the next round of selection, exclude that from the “get all actors” then set that variable to the new selected actor. This way the location can be reused but won’t be selected twice in a row

BP_BOX

Level BP

Create Box
Excludes last used area.

1 Like

Thank you all for your help. I tried everyones suggestions and decided it would play better if I just destroyed the SpawnLocation actor the box is being created to. I set the index object as a VAR and the call it to destroy it after the dispatch event. Keeps it so the location can’t be spawned again and I can make it work my idea.

1 Like

random thought. i would make it so that “create box” returns the created box. getactorofclass might return something else if there are two boxes.

also i’d personally make it so that the spawn locations spawn the actors. not the level bp. but i haven’t thought it up in detail.