Best way to make a weighted table for random level selection?

Hi All

I’m extremely new UE, so please forgive my lack of knowledge.

I’m learning while trying to develop a game concept.

My game would have multiple levels in it and for example I would like my character to go through a door and the next level that s/he enters in is randomly generated from a weighted table of levels.

Each level would have a “rarity” and thus more rare levels would spawn less frequently.

Ideally I would like some checks in place before that to eliminate some rooms from the “pool” if a condition isn’t met yet “say no key for room 3”, so it isn’t an option until the key is obtained.

I’m not expecting anyone to write the blueprint for me, just some advice in the right direction would be greatly appreciated.

Cheers!

A simple system would be like this. Have a map with the level names and weighting:

348077-screenshot-3.jpg

Then just make an array of the names, inserting each name the given number of times ( making it more likely to occur ). Then choose one randomly:

If you don’t want a level to occur, you can just set it to zero before doing this:

348079-screenshot-4.jpg

4 Likes

Wow, that’s a lot more of a comprehensive reply than I was expecting, thank you so much.

I’ll get to work to implementing it and testing.

You add to table new index with lower range. With value of 2 it is 1… you at the end incrase chance to get this level. OK?

Ok, so I’ve tested this and it works, but I’m having real trouble with the third bit.

In addition to being able to remove a level from the pool I’d like reduce the frequency with which it occurs once it’s been pulled.

I created an actor with collision that calls this function from (ThirdPersonGameMode) and placed that actor in each map.

I used the following code and set the map value for each level to 2.

I can go from map to map, but I can still pull the same map more than 2 times.

My current code is as such:

I’m not sure what you’re saying. I think I’m using clamp in the wrong way, be even removed it still doesn’t work as intended.

I wanted to prevent the count going below zero.

I’ll have to branch out an option for when zero is reached, but i still would like a reducing probability of that level reappearing after it’s been called once.