Calculate Percentage Off 100

If I get your question you have to use the “Random integer in Range” between 1 and 100 ( Random Integer in Range | Unreal Engine Documentation )

connect the output pin to the first pin of minor node (<) and your function’s pin to the second one. Connect the boolean pin to your output pin and is done.

BTW in this way you can spawn nothing (you can miss the 20% all the time), I suggest you an other way, I code it and I’ll send you a pic.

With this example you can spawn an actor between X with a certain % (the sum MUST be 100).

This is the function (Integer array as input, Integer as output)

this is how to use it.

i have so a spawner spawns 3 different actors into game depending on chance, i want to have a custom function determen what the chance is every time the function gets call, for ex

Input (20)

20%100

i get the number
now what?

Output (true/false)

Let’s say you want a 20 percent chance of something happening, the way I usually do it is:

  • Generate a random number between 0-100
  • If that number is smaller than 20, return true
  • If it’s bigger, return false

Quick and easy way of doing it.

EDIT: argh, beaten to it.

Well that’s the problem with wanting something to happen a certain percentage of the time, isn’t it? There’s a chance you’ll get a 100 misses in a row, but that’s just the way it works.

Can you elaborate on how this works better than the other proposed solutions? It seems like a more convoluted way to achieve the result and more prone to errors as well.

This one give a COMPLETELY DIFFERENT result. It take in input a table of %, generate a random int and return one of the indexes. If the element is bigger than an other there’s a higher chance to get it and you CAN’T spawn nothing. Actually it works (fine) only if the sum of the elements of the array is 100, if the Random integer in range node get in the max pin the sum of the elements it become flawless, but in the answer he asked the percentage off 100 and I forgot to improve it.

You was a little vague describing your problem, I’m not sure if this is what you want, BTW this randomly chooses one of the three depending on the percentage.

well where do i drag pins to the spawn actor?

what happens if the number == 20? if you return false your code would not work for 100%; if you return true it would not work for 0%