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"

Issues with Actors overlapping when spawned in random locations!

Hey! I'm trying to spawn a bunch of randomized objects at random locations in an area, but of course if you truly randomize locations you run into the issue of objects spawning on top /inside eachother. I believe I created a function that should fix that issue in theory, but somehow the actors are still spawning inside eachother. alt text

You can ignore everything outside the red box, its just debug stuff. So my BP consists of an event with a for loop (for the amount of objects to be spawned). Each loop a function is called that returns the randomized class, location and a bool if it is allowed to spawn. This is then used to spawn an actor. alt text

Now it gets a bit tricky. To calculate the locations and set the class i'm using 3 functions, one of which is recursive. It's basicly Event-> Random Class and Location -> Free Spawn Location (recursive) -> Is Space Empty?.

So the first one calls Free Spawn Location and passes the values to the return nodes. It uses weighted Bools to choose 1 of 3 Classes "randomly". alt text

Let's get to the recursive randomized location part. I'm guessing the issue is whithin this or the next function. I'm creating a new vector from a random unit vector multiplied by 1000 in x, y dimensions and adding the spawner location so that they spawn around my spawner. Next I'm calling Is Space Emty? to see if nothing has spawned around that new random location yet. If it returns true i'm adding the vector to my CurrentSpawnLocations array and return it, else i'm going into recursion so it generates a new random location to try. If this fails for ~15 times I'm guessing there is no free space available anymore and I won't try again. alt text

Lastly Is Space Empty? starts by looping through my array of Current Spawn Locations. It checks if the new random location (created above) is whithin a certain distance to any of the previous spawn locations. If it found one it will instantly return false. If it completed without finding one it will return true. alt text So what do you think? Am I close to a solution, or am I terribly wrong in everything I do? ^^

Product Version: UE 4.21
more ▼

asked Feb 18 '19 at 02:30 AM in Blueprint Scripting

avatar image

31 1 4

avatar image ThompsonN13 Feb 18 '19 at 02:51 PM

why not just use the collision handling override on your spawn actor node. if you set it to "try to adjust location, dont spawn if still colliding" then it will try to adjust the spawn location to where theres no collision, if it doesnt find a place then it doesnt spawn the item.

i just did a test with it ny spawning more characters at my players location and it resulted in spawning 4 more characters before it stopped spawning more. that was with my character staying in one place and just repeating the spawn.

avatar image nonamed46 Feb 18 '19 at 03:11 PM

LOL well thats actually a great idea haha, thank you^^ i mean i still don't understand why it doesn't work my way :/

i will have to be careful to spawn an amount similar to what i planned in the first place, since the recursive function was there for a reason but i guess if i spawn a few more than before it should work just fine

avatar image ThompsonN13 Feb 18 '19 at 03:38 PM

i mean you could create your own method and script it but it just seems easier to use the built in functionality.

then again you could have created a function like in the picture below. the function i created takes in a location and checks for overlaps there, if theres a overlap we run the loop again, if not we break the loop and return the location and if its good.

alt text

capture.png (228.4 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
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