Unreal Engine 4 Tutorial - Weighted Loot Table

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2024

ความคิดเห็น • 60

  • @RyanLaley
    @RyanLaley  4 ปีที่แล้ว +26

    EDIT: in the Choose Loot function you should use a less than or equals (

    • @germanslice
      @germanslice 4 ปีที่แล้ว +3

      What about also a level progressive loot table? (sword starts to appear at level 10, magic staff appears at level 20 (this is needed for progressive rpg's where the loot drops improve as you start to level up in the game.). Certain loot items will show up at certain levels you reach....Even valuable rare items...
      But since I'm using his Levelling Component System I'm having trouble getting his loot drop Component system to work with it. I will check the videos so see if he has put up a video to show how it works with his levelling up component
      system because it needs to work with his levelling up system.

    • @mr49000
      @mr49000 4 ปีที่แล้ว +5

      @@germanslice Wouldn't in that case have the class of items in the Key of the Map variable and then before they're rolled they're checked what level requirement it is for the drop. That variable could just be in the class of the item which is in the key?
      So the loot is rolled -> check if the {key} item class's level requirement for dropping is then continue the loot roll as shown?

    • @ryanbayley6139
      @ryanbayley6139 3 ปีที่แล้ว

      I think the follow up video would he perfect. Thank you for your time, great stuff 👍

    • @crossmr
      @crossmr 3 ปีที่แล้ว +2

      @@germanslice Level progressive is easy enough. You just need to add a function that adds loot with a specific weight as you hit each level. When a player levels up just check for new loot to be added to the table.

  • @LAxemann
    @LAxemann 3 หลายเดือนก่อน

    Great tutorial!
    As someone in the comments mentioned, this approach would always favor items with lower array indices.
    To solve this, one could loop through the options and us the "Random bool with Weight" as a breakout condition (after the weights have been calculated and assigned).

  • @mbwilding
    @mbwilding 3 ปีที่แล้ว +4

    Ended up making it a map with classes:float
    Selected my BP_PickupBase as the class then added the children pickups to the map.
    Then connected the output to spawn actor connecting the class output directly to it.
    Worked perfectly, thanks so much.

  • @SamFuller1989
    @SamFuller1989 4 ปีที่แล้ว +2

    It's actually kind of insane how perfectly this resolves an issue I've been having with a randomized limb-damage mechanic I've been working with for the past couple days. Yesterday I finally came up with a solution that worked for me, but it's nowhere near as easy as the logic you have for this loot drop system! Thank you so much for sharing this, I can't wait to replace my logic in favor of this! Not to mention I had no idea about actor components, so that's a nice bonus!

  • @ikebroflovski7088
    @ikebroflovski7088 3 ปีที่แล้ว +2

    Thank you for the tutorial. I would be very happy to see it not with a string, but with items (weapons etc)

  • @djshiro82
    @djshiro82 4 ปีที่แล้ว +9

    Having them show on ground would be great

  • @Assassin0314
    @Assassin0314 4 ปีที่แล้ว +2

    im new to unreal, and your tutorials are very practical and useful!

    • @RyanLaley
      @RyanLaley  4 ปีที่แล้ว

      Happy to hear that!

    • @basemosquit1776
      @basemosquit1776 8 หลายเดือนก่อน

      @@RyanLaley is there a way i can put this into uefn? or can i just make it in ue and then paste it into uefn (uefn is very limited)

  • @AGGStudios
    @AGGStudios 4 ปีที่แล้ว +4

    !!FOR ANYONE WHO NEEDS HELP GETTING THIS CODE TO WORK WITH AN ACTOR LOCATION!! An actor dies, this code runs to spawn something where it died.
    Say you want this code to be called when an actor gets destroyed, I am currently using this for my little game and it works flawlessly. Here is a link to the simple steps you need to follow. Ryan if you see this, thank you so much for this. I hope this could help people as well!
    Picture tutorial: imgur.com/gallery/apABjgf
    This is essentially all I had to do, after the Choose loot event, I plugged in my enumerator which just lists all of my types of pickups/collectables. This could be different depending on what you need this code to do of course. Plug that into the switch, as I have in the image, and run a spawn actor event for each of the nodes. Use a Get Owner plugged into a GetActorLocation and plug that into the location for the Spawn Actor, and you should be set! Move over to the actor that will be dropping the loot, ensure the loot component is already on that actor of course, then just plug in the Drop Loot event, and it should work perfect!

    • @FurMuzzleGames
      @FurMuzzleGames 2 ปีที่แล้ว +1

      Im really, REALLY surprised that no one liked or commented in a year.... this comment took me around 15min to figure out where and what to do. After that it worked perfectly. Thank you sir.
      Not all heroes wear capes

    • @itanocircus2077
      @itanocircus2077 5 หลายเดือนก่อน +1

      Thank you for showing this off! Works like a charm.

  • @reeanimationgaming1034
    @reeanimationgaming1034 4 ปีที่แล้ว

    This is fantastic... So far I have just put loot into a list, and if I want an item to be more rare, I was adding more of all the other items, getting a super long list in the end.. I will give this a shot, Thank you very much!!

  • @richmakesgames
    @richmakesgames 2 ปีที่แล้ว

    This worked great! Thanks! For some reason I could not get the last item in the list to spawn. The result was always -1 , even if I set everything else to 0 and the last one to 100. The Only way I could get it to work properly was to add 1 extra item to the list with 0 chances, and it works perfectly! No idea what I did wrong, but I thought I'd share this in case someone else was having a similar problem. (I was using Integers instead of floats, maybe this was the issue?)

  • @حاتمإسماعيل-ب7ر
    @حاتمإسماعيل-ب7ر ปีที่แล้ว

    Did you made the video you were talking about?

  • @glosmolt
    @glosmolt 4 ปีที่แล้ว +3

    Hey thanks for this video! One question, is this supposed to be the proper way to get a fair randomness? I mean, wouldn't the last objects on the map list have less chances of getting chosen due to the iteration order?

    • @RyanLaley
      @RyanLaley  4 ปีที่แล้ว +1

      This is the way to get fair randomness and the correct way to do it

    • @glosmolt
      @glosmolt 4 ปีที่แล้ว +2

      @@RyanLaley This is extremely helpful and less cumbersome than any other methods, so thanks a million! :)
      I Would like to paste a raw C++ example version here in case someone is interested (with an Enum type instead Strings):
      void ULootGenerator::GenerateLoot(TMap LootTypeChances, int32 LootLevel)
      {
      float SumChances = 0.0f;
      for (auto& Elem : LootTypeChances)
      {
      SumChances += Elem.Value;
      }
      float RandomValue = FMath::RandRange(0.f, SumChances);
      for (auto& Elem : LootTypeChances)
      {
      if (RandomValue

    • @theHermitCollective
      @theHermitCollective 2 ปีที่แล้ว +1

      ​@@RyanLaley Even though it seems like since an array always runs in the same order, a high value at the beginning of the array will always return true over a low value at the end of the array, this method still works. I mean you can test it. Put two values in a table. one at 10 at the front of the array and one at 1 at the end of the array. it will return a fairly predictable spread of those two values. Then flip the values, putting your 10 tickets at the end of the array and the 1 ticket at the front. And it still works.
      There's something about this I'm not understanding - my brain can't get past the idea that a high value at the front of the array would always return true

  • @Christopherseander92
    @Christopherseander92 3 ปีที่แล้ว

    This is exactly what I was looking for, thanks for sharing

  • @moragna
    @moragna 3 ปีที่แล้ว +1

    As always - thank you for the vids! thought I would share that I just tried dragging your "LootTable" from the youtube video into my BP... guess I need another coffee LOL

  • @ihusitusi
    @ihusitusi 4 ปีที่แล้ว +2

    Would you like to cover how to create weapons with different parts randomized on the weapon?

  • @captainsavage5816
    @captainsavage5816 4 ปีที่แล้ว +1

    Hi Ryan, will you be making a video about dropping loot into the world (perhaps from monsters)? Still very interested in seeing that. Thanks!

  • @ex_draco3017
    @ex_draco3017 4 ปีที่แล้ว

    It's simpler than I thought

  • @ty_teynium
    @ty_teynium 4 ปีที่แล้ว +1

    Hello Ryan! Can you do something on finding the best way to Sort an inventory and by different categories like most amount or alphabetical order or rarity and price?

  • @xantishayde-walker4593
    @xantishayde-walker4593 4 ปีที่แล้ว +1

    Plz do the Second Video to handle spawning of items in the world.

  • @FF-FAN9999
    @FF-FAN9999 ปีที่แล้ว

    good stuff. thank you Ryan

  • @MadpolygonDEV
    @MadpolygonDEV 4 ปีที่แล้ว

    in your case, if you changed up the values, wouldnt you sometimes get more loot when the condition meets on more than 2 items?

  • @trayvonray9614
    @trayvonray9614 2 ปีที่แล้ว

    Great tutorial

  • @ZL1704
    @ZL1704 2 ปีที่แล้ว

    Great Video! Helped me out a lot! Thanks (:

  • @Xperto_
    @Xperto_ 4 ปีที่แล้ว

    I just got a random notification for this video

  • @eminimamoglu3072
    @eminimamoglu3072 4 ปีที่แล้ว

    Great tutorial. Thanks

  • @An0therR0gue
    @An0therR0gue 3 ปีที่แล้ว

    is it possible for a random item/items in a container to respawn after either x amount of time or when the player is x distance away from the container? they can also be different random items.

  • @thabudmaster
    @thabudmaster 2 ปีที่แล้ว

    As a newbie I love this, any chance of doing the datatable version with loot dropping into the world? Thx! 👍🏼

  • @dawnrigel4255
    @dawnrigel4255 3 ปีที่แล้ว

    Was able to follow along fine until the end. For some reason, I can't add the Loot Table actor as a component to my enemy (doesn't show up when I search for it). I can drag and drop the Loot Table from content browser, but I guess that only does so as a child, which is causing some connection issues. Don't know if this is an engine difference or not, but I'll try and manage!
    *2 seconds later*
    *Sees that I'm using Actor instead of Actor Component :)*

  • @kingpoki1954
    @kingpoki1954 2 ปีที่แล้ว

    How would i go abour spawning the loot from a string?

  • @michaelsparkson
    @michaelsparkson 2 ปีที่แล้ว

    Not sure what Ive messed up but it just drop the 1st item on the list every time.

  • @sashanodiaart
    @sashanodiaart 2 ปีที่แล้ว

    Why is it Float and not Integer? Is there anything that Integer would break?

    • @richmakesgames
      @richmakesgames 2 ปีที่แล้ว

      I'm using Integer instead of a float, and for me it works fine. I was having an issue (see my other comment) where it wouldn't select the last item in the list. But adding an extra item with 0 chance fixed it for me. I suspect it has something to do with using integers.

    • @jdia.
      @jdia. 2 ปีที่แล้ว

      Floats have decimal places, which could help refine the amount process. A 10.3 could be better or worse in a case than a 10.5. You get all the extra chances in between whole numbers, like a percentage.

  • @II-er7gj
    @II-er7gj 4 ปีที่แล้ว

    Hi, Ryan! Can you make tutorial how to loot dead bodies in game? For example freshly killed soldiers or zombies to take a gear like backpacks, guns, ammo etc away from them to move stuff from they inventory to players inventory? That could be very nice! :) :) :) :)

    • @funker9002
      @funker9002 4 ปีที่แล้ว +1

      I Would follow his inventory tutorial, and make a death event for your enemy that adds an inventory component with the loot in it

  • @MrSmith01
    @MrSmith01 4 ปีที่แล้ว

    Your channel is treasure chest with loot.

  • @1AnimeFinder
    @1AnimeFinder 3 หลายเดือนก่อน

    can u do a drop in world plz

  • @az-ru2084
    @az-ru2084 ปีที่แล้ว

    your content is help me so much but opening music is way too loud

    • @az-ru2084
      @az-ru2084 ปีที่แล้ว

      random value could be 0.5 which is less than gem 1.0 so do we need another loops for that case?

  • @DarthBiomech
    @DarthBiomech 3 ปีที่แล้ว +2

    It feels like this function will be weighted to output less of the items in the first part of the map table, and more of the items in the second part of the table, regardless of their actual value, since the probability of the random number being less than the map member's value is lower when it's the first in the list compared to when it's last in the list (and to add to that, the later list members have less chance to be selected because there are more items before them that can snatch away the selection, which makes the whole thing even more uneven).

    • @benikeler
      @benikeler 2 ปีที่แล้ว

      Literally thought the same thing when I first saw this vid, but the math checks out. If you haven't already, try a test. Build this same function, but make a map variable that has A, B, C, D, E for the keys and give them all a value(weight) of 1 so each has an equal chance to occur. Bind the function to a button or key and slap it a couple dozen times. Voila! It works lol.

  • @MadpolygonDEV
    @MadpolygonDEV 4 ปีที่แล้ว +1

    10:11 I am really confused, if you say you have 12 as a random value and then you say mace(10) is greater than 7 then you wouldnt still get mace would you? You re not breaking the loop therefore wouldnt the loop go on and the value 7 would get subtracted by 10 again, which equals -3 and you would technically get all 3 items below that? You didnt explain that very well.

    • @RyanLaley
      @RyanLaley  4 ปีที่แล้ว +2

      The return node breaks the loop. So when it becomes lower then it outputs that item.

  • @jwalinadhyaru2218
    @jwalinadhyaru2218 3 ปีที่แล้ว +1

    How can I make a karma system where doing certain tasks will increase the chances for the drop or much rare items and doing bad stuff a lot might end up in getting no loot at all ?

  • @ElectroForge115
    @ElectroForge115 3 ปีที่แล้ว

    Follow Up?

  • @jestersheepy511
    @jestersheepy511 3 ปีที่แล้ว +1

    If you had two items that shared the same amount of tickets, this will always choose the first of the two in the list. Rather than outputting the first true result it could build a second array of 'true' results and randomly pick a winner from that.

    • @EmperorVigor
      @EmperorVigor 3 ปีที่แล้ว +1

      Correct me if I'm wrong but wouldn't it only choose the first of the two if the random value was low enough? Say that you have 2 items in your loot table, both have a value of 5. Then the total is 10. A random number of 1 to 5 would always pick the first item in the list, but a value of 6 to 10 would never pick the first item. If you have a die with 10 sides and toss it, every number would represent 10% of the total sum (10 numbers). You're as likely to roll a 2 as you are to roll a 10. So with the loot table from the video you'd have a die with 20 sides and each result would represent 5%. You'd have a 25% chance to loot a helmet. Is that flawed and not random?

  • @ihusitusi
    @ihusitusi 4 ปีที่แล้ว

    pogchamp

  • @axvex595
    @axvex595 4 ปีที่แล้ว +1

    Follow up Please 😁👌