Random captureable NPC spawn in set radius around player

Hello, I’m relatively new to unreal engine 5, I’ve created a couple of games and have started a fairly large project I’ve been working on for quite a while now. However, I’ve now reached a point where I’m doing stuff I haven’t had practice with and all online tutorials show me the gist but don’t explain it or give more options to what I want to complete. I’ve attempted to do it myself without tutorials but just can’t figure it out and even if I do, I’m sure there’s a much more efficient way of going about it.

So the situation is, I have a small creature NPC that the player can capture, however, I need to create a random spawning system so that they spawn in a set radius around the player (I was thinking of using GetRandomReachablePointInRadius). However, where the tutorials lose me is I need them to spawn in a set probability ranging from common to Legendary.

By the way, I have already created an inventory system so all the creatures have already been denoted a rarity by integer if that’s useful.

If anyone can give any input on this or needs to know anything else please reply/comment

Hey downofwar5000!

So what you can do here is use a Random in Range (Float) node. You can do something like this:

So the “Common” and “Rare” variables are checked. Say you get a 700 and common is set to 500. This will return false for Common, and move on to asking if it’s Rare. This can be chained as many times as you need to have your different rarities!

1 Like

Thanks for replying! I’m not home at the moment but I’ll do this the second I do, your method makes way more sense than what I came up with. Can’t thank you enough, was stuck on that for a while.

Of course @downofwar5000!

That should work fine, I don’t know if it’s going to be the most efficient organization-wise, but the processing hit is very small. If anyone else has any better ideas for this, I’m all ears as well!

@Mind-Brain I believe I’ve created a system to spawn a random slug, just wanted to run it by you to see if it would work properly and if you think there could be a better way to go about it. I’ve taken some inspiration from your design towards it:

each creature is assigned an integer
get random float in range, eg range common = 0-24 then rare = 25-38 …
loads of branches for each integer corresponding to each creature’s number

Would that work?

Almost @downofwar5000!

If you’re using integers, you’ll want to make sure to RoundToInt after the RandomFloat and set that instead of setting a float! Then use that Random Integer you SET (Make sure to set it before the branches and use that variable or it’ll make up a new one every time it’s called) As long as they go in order going up and you’re using Less than or Equal To.

Since you’re using Integers, make sure the Min on the RandomFloat is your lowest integer (So if you don’t use 0, make the lowest number 1) and make sure the highest Integer matches your Max on the RandomFloat!

hey im on 4.27 ue, cant find the set rarity function, its hte 3rd one
is only for latest unreal?

Hey @locateli!

Are you talking about the “Rand Rarity#” it’s a variable float. It was just created and named for this specifically. I don’t believe any of this is unavailable in 4.27 :slight_smile:

If you’d like to talk about it more, please make a new post with a link to this thread in the new post! :slight_smile: