Flexible LOOT SYSTEM in Unity with Random Drop Rates

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 89

  • @mandamoon9149
    @mandamoon9149 2 роки тому +19

    A book, a fish, and a gem walk into a bar….. and Bmo’s at it again with that good content

  • @arturoescobar4226
    @arturoescobar4226 2 роки тому +3

    Soo useful, I will definitely going to use this for my next school proyect, thank you so much and keep up your amazing videos. Really helps me and other beginners a lot.

  • @nikaman9539
    @nikaman9539 2 роки тому +1

    Im so lucky that i picked up Unity again after years during the time u have started uploading content mate

  • @sn0man
    @sn0man 2 роки тому +5

    Great lesson here. Very clearly shows the fundamental to getting an RNG loot system in place.

  • @seaderwerks3046
    @seaderwerks3046 Рік тому

    I've watched several of your videos.
    This is the one that got me to subscribe. Thank you for this. Simple, effective and easily modifiable.

  • @xyphelon
    @xyphelon Рік тому

    Epic Video, Just found your channel, trying to figure out some stuff, magically it appeared. Great Content!!!! Hope your channel grows

  • @FullMe7alJacke7
    @FullMe7alJacke7 2 роки тому +1

    Underrated channel! Keep up the excellent content

  • @SelaMalka
    @SelaMalka Рік тому +1

    Very nice!
    And now I'm gonna steal it.
    Thank you!

  • @Jona69
    @Jona69 2 роки тому +1

    Hey man. I just found your channel and I love you tutorial style. Very helpful!

  • @Філіпс-й4ш
    @Філіпс-й4ш 2 роки тому +1

    At right place, at right time! Thx for tutorial)

  • @mitchellknirnchild8285
    @mitchellknirnchild8285 2 роки тому

    Hey, your tutorials are amazing and you deserve millions of subs.... Loving watching and learning from you so far!!

    • @BMoDev
      @BMoDev  2 роки тому

      Appreciate ya

    • @sr_ber1816
      @sr_ber1816 Рік тому

      @@BMoDev hello in your video Easy Ammo & Reloading System in Unity i have a problem in end first code you put weapon.Reload but you dont share something with weapon and console drop me error i dont have idea how cant i fix this pls help

  • @spd9190
    @spd9190 2 роки тому +18

    Fantastic video. I saw a few comments below asking how to differentiate the items since they all drop from the same prefab. For example in my game I want the items to have a different effects when the player picks them up. I added this line of code to your script under the InstantiateLoot function in the LootBag script to add a tag to the prefab depending on what the lootName is. From there you can just add an onCollision function in the player script to react to the tagged item. Hope this helps
    public void InstantiateLoot(Vector3 spawnPosition)
    {
    Loot droppedItem = GetDroppedItem();
    if(droppedItem != null)
    {
    GameObject lootGameObject = Instantiate(droppedItemPrefab, spawnPosition, Quaternion.identity);
    lootGameObject.GetComponent().sprite = droppedItem.lootSprite;
    //assign tag function
    if(droppedItem.lootName is "Shield")
    {
    lootGameObject.tag = "Shield";
    }
    }
    }

  • @happyghoststudios4237
    @happyghoststudios4237 2 роки тому +1

    Great video! Very helpful! I am very enthusiastic!!!!

  • @HrSkully
    @HrSkully Рік тому

    Very Helpfull and good Tutorial!!! Thanks a lot! It is exact what i needed

  • @CokeVoAYCE
    @CokeVoAYCE Рік тому +1

    thanks. easy, simple, complete and concise.

  • @Kylenavyify
    @Kylenavyify 2 роки тому +1

    You, sir, have earned my sub and like.

  • @thenubblet3925
    @thenubblet3925 2 роки тому +2

    this is a really cool way to do loot
    your video's often show me better ways do do simple process and systems, all your systems are easily expandable to suit more complicated games
    if you love rng and wanted to a random amount of loot to drop you could put the whole of GetDroppedItem inside a for loop and roll the limiting INT to decide how many times it roles for loot

    • @BMoDev
      @BMoDev  2 роки тому +1

      Great idea, and thanks for that!

  • @Raydamick
    @Raydamick 2 роки тому +2

    hey I was just wondering how to differentiate the items from each other, since they all come from 1 prefab

  • @JERSCOM
    @JERSCOM Рік тому +1

    If you want to do this in a 3d game, like me that I'm currently doing an rpg, all you have to do is change the sprite variable in Loot for GameObject

  • @emanueltejadacoste2250
    @emanueltejadacoste2250 2 роки тому +1

    Nice video, you always bring useful tips and features, for some reason is kind of low quality, 360p max , not a big deal but felt kind of empty

    • @BMoDev
      @BMoDev  2 роки тому +1

      Thanks appreciate that, it looks like it goes to 1080p now, you may have caught it early enough when it was still processing

    • @emanueltejadacoste2250
      @emanueltejadacoste2250 2 роки тому

      @@BMoDev Oh yea, nice! I'm sorry I said bad quality instead of low resolution or some XD

  • @viktorpavlovskiy2120
    @viktorpavlovskiy2120 Рік тому +2

    how can I adapt this for 3D?

  • @Whopen
    @Whopen 2 місяці тому

    it says list doesnt have a definition for lootsprite what do i do

  • @AceAmStiel
    @AceAmStiel Рік тому

    isnt the dropchance of a low dropchance item way worse? if i have 100 items in the lootlist i first need to hit lets say a 2% dropchance and then need to roll the item in the lootlist again? so i roll twice for one item?

  • @maheshcharyindrakanti8544
    @maheshcharyindrakanti8544 2 роки тому +1

    Ty I got my first divine because of you

    • @BMoDev
      @BMoDev  2 роки тому +1

      Idk what that means but I'm glad

  • @toddietubby7450
    @toddietubby7450 Рік тому

    for some reason when the loot scriptable objects have the same dropChance value only one of them ever spawns and cancels out the other

  • @mayesawidiandita1434
    @mayesawidiandita1434 Рік тому +1

    How do you write a function to retrieve loot items?

  • @DijbanCyclone
    @DijbanCyclone 2 роки тому +1

    i would love a tutorial for an shop system like enter the gungeon or neon abyss

  • @pablogoni6267
    @pablogoni6267 Рік тому +1

    is there a way that instead of using sprites use a gameobject?

  • @feelmacan
    @feelmacan Рік тому +2

    I checked that the code is running well.
    By the way, how can I modify the code to randomly drop prefabs instead of sprite files?

    • @darkbatu
      @darkbatu Рік тому +1

      same problem here haha

    • @toddietubby7450
      @toddietubby7450 Рік тому

      i'm a real noobie so take my advice with caution, but the way i did it was to add a public gameobject prefab reference to the scriptable object, then instead of instantiating DroppedItemPrefab, i spawn the droppedItem.prefab since the dropped item variable IS the scriptable object you can access the prefab from there;

  • @darkbatu
    @darkbatu Рік тому +1

    how can works for 3d objects?

  • @WeirdGoat
    @WeirdGoat Рік тому +1

    The only thing I found missing is putting items in a pool, just in case you have lots off loot on the screen, add a switch, then you can easily use this in your other projects

  • @lunaris356
    @lunaris356 2 роки тому +2

    Hey BMo! So I'm trying to figure out a way to return the dropped item, while keeping the ability to drop multiple items at the same time? Help would be appreciated, love the video so far!

    • @lunaris356
      @lunaris356 2 роки тому

      @Nevu Abo No I have not sadly, I'm pretty inexperienced and haven't had much time to test it out being busy with school.

    • @McAVGamer
      @McAVGamer 2 роки тому

      Same, if you got solution please update.

    • @mmmargh4743
      @mmmargh4743 2 роки тому

      Can you be more clear please? I'm not sure to understand your issue

  • @blenderinc.4402
    @blenderinc.4402 3 місяці тому

    Why arent there 2xn lists for the unity editor? or is there a way to get one?

  • @totallyoffgrid3008
    @totallyoffgrid3008 2 місяці тому

    I am really struggling with this….Lol. If I have a boss, and I want a particular piece of armour to drop from only that boss…. Do I just attach the script to the sprite?

  • @NgocHo98
    @NgocHo98 2 роки тому +1

    Thank you Sir
    Can you make a video how to make a Quest system ?

  • @Spider_In_The_Ditch
    @Spider_In_The_Ditch Рік тому

    That last line of code obliterated my game for some reason. Is there a way to use a game object instead of a sprite.
    I fell asleep last night thinking about going how I may take your use of a number generated system and apply it to my game. Thankfully I only had two drops, so what I did was took the way you did the number generator added it to my enemy controller script in the section where if the enemy's health gets to zero, they die. So, I added an if statement (which states) if a number from less than 10 is chosen than one item drops (I used an enemy drop sequence that had worked for me prior) and if a random number greater than 91 is chosen than the other item drops.
    Even if your tutorial wasn't completely compatible with my game. You still taught me some of the building blocks which allowed me to add a feature I have been wanting to add to my game. Thanks!

  • @MeloDev-ll9yi
    @MeloDev-ll9yi 6 місяців тому

    That's really cool, but I think you shoud make a random throw the sum of chances. And in this case if u want to make empty drop simply make a null field.❤❤

  • @Su-qm6ge
    @Su-qm6ge Рік тому +1

    I really love your code but I stuck on drop more than one item like one enemy died is drop 2 gold ore and one gold bar can u please help me to make it or explain me to do it Thank again for your wonderful code. :)

  • @ThePoePoee
    @ThePoePoee Рік тому

    how do i incorporate this with the inventory system

  • @Batak-dg4gc
    @Batak-dg4gc 2 роки тому +1

    First thing first bro thanks for the vid but i have a question.when i drag my sprites the list not accepting it can you help me please?

  • @neffthepanda
    @neffthepanda Рік тому +1

    trying to integrate this into Coding With Unity's inventory system tutorial but having a really hard time

    • @neffthepanda
      @neffthepanda Рік тому

      I actually figured it out. With that tutorial you already have scriptable object called ItemObject. You can just use that data instead of creating the loot script. Then add the ItemObjects into the lootbag and instantiate them when the enemy health is >= 0. Still used the drop chance too.

  • @KRAXi-
    @KRAXi- 2 роки тому

    Hey man im loving theses tutorials. I have one question in the how to get an enemy to chase you in unity tutorial i have an issue with the public static event ActionOnEnemyKilled; code it pops up an error saying Assets\Enemy.cs(7,25): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?) im pretty new to all of this and i have no idea how to fix this. i cant progress threw the tutorials becasue im stuck ont this part. However theses are awesome and simple thank you! keep it up

  • @tiendatnguyen20602
    @tiendatnguyen20602 11 місяців тому

    My gem always move when it was created and not stop like you ?? how can I fix this

    • @ECAKJ
      @ECAKJ 9 місяців тому

      up the mass and friction in rigidbody

  • @jaydenvogt1286
    @jaydenvogt1286 2 роки тому

    Great lassen i love und top down shooter tuts .❤
    Can u please do next time how to make a high score or Player health or a enemy spawner

  • @davidabris
    @davidabris Рік тому

    Hello I have a question: Is it safe to use public for lootList? Can't it modified by a player?

  • @cheetah7887
    @cheetah7887 2 роки тому

    hey bmo how can i pick up the items that dropped like an ammo box

  • @itsspider6156
    @itsspider6156 Рік тому +1

    my items dont stop moving, why?

    • @jackselhpdepr2892
      @jackselhpdepr2892 9 місяців тому

      Same if i found a solution i will let you know

    • @jackselhpdepr2892
      @jackselhpdepr2892 9 місяців тому

      Hey i found it, for me when i put 4 on the Linear drag (on the Rigidbody2D) it solved my problem, you can try adjusting that and see whats work for you

  • @voltex9157
    @voltex9157 9 місяців тому

    thx a lot, but how i use them? like add script to the loot so i use them

  • @MarstonBoii
    @MarstonBoii 2 роки тому

    Hey BMo! Is there a chance to get a tutorial on Quick Time Events in Unity, please?

  • @TheLunarah
    @TheLunarah Рік тому

    Thank you

  • @MGameDev22
    @MGameDev22 Рік тому

    Can i use this for a 3d game?

  • @boboyedaniel9660
    @boboyedaniel9660 2 роки тому

    As always, everything is super. Waiting for new cheats from your side

  • @renwilliams59
    @renwilliams59 Рік тому +2

    For those wanting to do a 3D object instead of a Sprite, it's SUPER easy:
    Delete the two references to the sprite (the public variable in Loot, and the lootGameObject...sprite = droppedItem.lootSprite in LootBag).
    Create the item you want dropped in the world as you normally would. So drag a 3D cube to the screen if you want to drop a cube. Fix it up however you'd like and create a prefab out of it (i.e. Drag it into a folder in your assets)
    Whatever Object has the Loot Bag Script attached to it, change the Dropped Item Prefab to that new prefab you just made (so don't use LootPrefab, it was just an example item).
    And that's it! Since nothing is referencing a sprite, it'll just drop the whole object.

    • @AceAmStiel
      @AceAmStiel Рік тому +2

      wouldnt that just allways drop the new prefab you created?

  • @tomkc516
    @tomkc516 2 роки тому

    We need more videos!

  • @dariuszwesierski1928
    @dariuszwesierski1928 Рік тому

    Like always. not working in my engine xD even GPT says code is writed good. but when i have other system like items, inventory, equipment, then something must go wrong ;/ ehh

  • @Laserbeanification
    @Laserbeanification Рік тому

    Hey I have been enjoying your tutorials. I'm curious if you plan on returning?

  • @Stompin40
    @Stompin40 Рік тому +1

    Pog

  • @NotTolik708
    @NotTolik708 2 роки тому

    it's genius

  • @Billioncompany786
    @Billioncompany786 2 роки тому

    Hey!
    Can you make Tutorial on Monopoly/Businessman Board Game in Unity 2D ?

  • @T3QN1Q
    @T3QN1Q 2 роки тому +2

    GIVE ME ALL YOUR LOOT

  • @petervandeheuvel7322
    @petervandeheuvel7322 Рік тому

    3 everyday.

  • @headed_weast
    @headed_weast 2 роки тому +3

    If: ( blueEyedParents == true) {brownEyes(loot).dropChance = 0.00000000001};
    Else: return;

  • @acatatofr
    @acatatofr Рік тому +2

    the problem of this system is that this doesn't show real chances, like if there 70% rare item and 100% rare item, it would turns out, that 70% will pop up more times then 100%

  • @lee1davis1
    @lee1davis1 Рік тому

    This video was just another regurgitated remake of other vids. So missleading.

  • @GamingGables
    @GamingGables 2 роки тому +1

    Awesome video! I had a question on using this for 3D game objects. Instead of using "GetComponent().sprite" could I use GetComponent()? Not sure what the equivalent would be when working in 3D. Thank you for your excellent content!

    • @heyuparry5152
      @heyuparry5152 2 роки тому

      did you solve the problem?

    • @TheJakeblake
      @TheJakeblake Рік тому

      That would not work since so would only be getting the Mesh with out textures, that get Component is so that the image in sprite render gets automatically serialized and so it can be shown in game, you don't have to use that in this case, you could just make a gameObject variable and manually serialize that on the inspector

  • @technofeeliak
    @technofeeliak 2 роки тому

    At this point there are options.
    At this point there is one option.
    Please correct your speech.
    You're going to encourage bad habits for your audience.

  • @TheLunarah
    @TheLunarah Рік тому

    I have this class in my lootPrefab, how can I access the name of the item there? I need somehow to access the lootName value
    public class Colectable : MonoBehaviour
    {
    private void OnTriggerEnter2D(Collider2D collision)
    {
    Debug.Log(gameObject.GetComponent().lootName);
    if(collision.tag == "Player")
    {
    Player player = collision.GetComponent();
    if(gameObject.GetComponent().lootName == "Coin")
    {
    player.coins += 1;
    }
    if(gameObject.GetComponent().lootName == "Experience")
    {
    player.experience += 1;
    }
    Destroy(gameObject);
    }
    }
    }

  • @acatatofr
    @acatatofr Рік тому +7

    the problem of this system is that this doesn't show real chances, like if there 70% rare item and 100% rare item, it would turns out, that 70% will pop up more times then 100%