How to choose random Actor Class

Hi! I have a script that spawns a gun, but I have 2 guns and I want them to spawn randomly. How can I do this?

1 Like

For choosing between 2 classes this is OK:

Don’t forget to connect the return value in your pic! And if you need more than 2:

But you do not get the weights. Admittedly there are numerous way to generate random results.

But then I can’t combine SpawnActor to my weapon object

341226-unknown.png

Cast return to Weapon Base.

Alternatively, you can also do it like so to get an explicit type out of the Spawn node:

Red arrows indicate the same variable of base weapon type.

But now what if I have more than 2 guns?

  • cast to weapon base class:

  • or use a switch:

Thanks a lot, you are the man!