Flexible Pickup / Collectible System in Unity With Events

  Рет қаралды 22,519

BMo

BMo

Күн бұрын

Пікірлер
@UnfamiliarLandsGame
@UnfamiliarLandsGame Жыл бұрын
Great tutorial. Full of solid programming principles that I really appreciate, especially given how easy to understand your videos are. One thing I'd like to point out is that I temporarily got tripped up because I don't think your video says which game object to attach the "Collector" script to. So at first I had it attached to the coin and it took a minute to realize that it only works correctly if the player has the "Collector" so that the collision is detecting the right game object. But thank you for making such a helpful video.
@muhammedemen5122
@muhammedemen5122 2 жыл бұрын
It's awesome. Our codes are spaghetti. This is very clean and SOLID and DRY code. Thanks and please more like this.
@Sam4Progress
@Sam4Progress 9 ай бұрын
This was a very informative video! I am going to have to learn more about Interfaces, and Events but this is right up the alley I am trying to put in my game!
@Stompin40
@Stompin40 2 жыл бұрын
This is really insightful!
@chipmunkninjah
@chipmunkninjah 2 жыл бұрын
Yours are the only tutorials I don't feel the need to play at incresed speed to avoid "downtime". That says a lot about how well-produced and well-paced they are. Thank you for making these widepeepoHappy The only think keeping this tutorial from being a solid 11/10 is the lack of timestamps.
@AngersFiction
@AngersFiction 2 жыл бұрын
Please keep up the great work, your method of explanation and no nonsense approach is extremely helpful
@BMoDev
@BMoDev 2 жыл бұрын
I got you
@suicune2001
@suicune2001 2 жыл бұрын
Interesting! I've never heard of interface before. It looks really useful. Thanks. :)
@BMoDev
@BMoDev 2 жыл бұрын
Theyre pretty important!
@suicune2001
@suicune2001 2 жыл бұрын
@@BMoDev I'm following a tutorial and he is using interfaces. Since you made that video, I can understand what he's doing. :)
@lamywater
@lamywater 2 жыл бұрын
Thanks man, what I was looking for and to the point.
@BMoDev
@BMoDev 2 жыл бұрын
Glad it could help!
@stefan429
@stefan429 2 жыл бұрын
FYI you can use properties instead of fields in interfaces if you really need them :)
@cheesyduck3553
@cheesyduck3553 2 жыл бұрын
Legend
@bobbville
@bobbville 2 жыл бұрын
Cool vid! 🔥🔥🔥
@superblue5871
@superblue5871 Жыл бұрын
Excellent tutorial, thanks!
@Electrochim
@Electrochim Жыл бұрын
Hey, thanks fro the tutorial but I have an issue : when I change scene in my game and come back, I can collect the collectable again, and I don't want that. Can you make a video about it please ?
@risingdagger5416
@risingdagger5416 Жыл бұрын
Mine doesnt debug at all , how do I fix it using System.Collections; using System.Collections.Generic; using UnityEngine; public class Collector : MonoBehaviour { private void OnTriggerEnter2D(Collider2D collision) { ICollectible Collection = collision.GetComponent(); if(Collection != null) { Collection.Collect(); } } } I did the exact same but not working Edited : Okay just realised that the collector script was suppose to be attached to the player.
@bastienbaivier3062
@bastienbaivier3062 3 ай бұрын
Thank you, i had the same problem
@risingdagger5416
@risingdagger5416 3 ай бұрын
@@bastienbaivier3062 np mate. It gets A little confusing at a later stage when implementing the other codes for your enemies, AI, and so on
@umapessoa6051
@umapessoa6051 2 жыл бұрын
You can also do on the trigger enter method: if(TryGetComponent(out ICollectible icollectible)) { icollectible.Collect() }
@dahstroyer
@dahstroyer 2 жыл бұрын
in the Icollectiable class it says the modifier public is not available
@tazman8487
@tazman8487 10 ай бұрын
You have a class specific to a Coin but that would mean having a different script for every object you want to be a collectable as opposed to having a single script that you can then use on any collectable item and then just add a reference to a scriptable object which tells the collector what item it is..
@IluXa4000
@IluXa4000 9 ай бұрын
You are right in terms of " the same wotk with every collectable". But if you need to have different logic on collect, then it would be much harder to determine logic that works with general Type and just using SO as type
@brady9621
@brady9621 Жыл бұрын
How to i save the coin counter over different scenes
@iken_ar
@iken_ar 2 жыл бұрын
Thanks This Really helped 👌👍
@officiallambs
@officiallambs 2 жыл бұрын
Amazing thanks!
@mandamoon9149
@mandamoon9149 2 жыл бұрын
I would trade in all my coins for this vid 💰Money my dude!
@nikaman9539
@nikaman9539 2 жыл бұрын
What if my loot is a scriptable object like in other videos?
@wearwolf4202
@wearwolf4202 2 жыл бұрын
So I'm a bit confused. How would I make what I would call a collectable shelf. A place in game you can go to and look at what you've collected. This would work right, if I understood the video correctly
@bortokan1784
@bortokan1784 2 жыл бұрын
how to trigger the collector script is it on the player or on the event system because when I try to collide with coin I'm getting no log message there is rigid on the player
@friedcrumpets
@friedcrumpets 2 жыл бұрын
Finally a tutorial that doesn't use scriptable objects for inventory/pickups. Funnily enough I've just been working through an ICollectable version of this before watching your video, love interfaces. I'm glad to see I'm on the right track 😁 It's really refreshing to see interfaces taught so well in such a bite sized chunk of information 👌 nice
@LostSol25
@LostSol25 Жыл бұрын
is it bad if i dont use a scriptable object for collectables?
@friedcrumpets
@friedcrumpets Жыл бұрын
@LostSol25 I don't think it's bad at all. At the time I made this comment I was working on something simple and really thought this was a good tutorial for it. With scriptable objects it's entirely down to the game your making and how deep the rabbit hole goes. You could still use an icollectable with a scriptable object item if you needed, although there are other ways.
@LostSol25
@LostSol25 Жыл бұрын
@@friedcrumpets Ohhh makes sense, thanks for getting back!
@bengamedev1872
@bengamedev1872 10 ай бұрын
Good stuff, although worth noting it's pointless to have interfaces if your dealing with just one or two. It makes code navigation more annoying / lengthier because of the detachments and any components working thorough interfaces quickly become welded as-is, since changing them could break every other consumer's assumption. But that goes hand-in-hand with interfaces 😅
@TheSlimHim
@TheSlimHim 2 жыл бұрын
What's your opinion the Collector doing the OnTriggerEnter2D vs the Collectible?
@KeyGameUniverse
@KeyGameUniverse 2 жыл бұрын
Can you make a part 2 with how to save and load these collectibles ?
@younesamir3674
@younesamir3674 2 жыл бұрын
Hey ! Were do you find binding of isaac sprite please ?
@simpleme6541
@simpleme6541 2 жыл бұрын
How to add different values to different gameobjects and then add them together. For example 1 gameobject worth 2 point and the other is worth 4. And if i collect, for example 10-10pcs of them, then the result is: X Thank you in advance.
@terablue80
@terablue80 2 жыл бұрын
Hiiiii! I'm so very curious how can I make an AR element collectible on tap? Is it possible? I searched the whole internet for a tutorial but no luck :(
@noisemaker0129
@noisemaker0129 2 жыл бұрын
What is a method and delegate
@izzu7641
@izzu7641 Жыл бұрын
Can i use this on 3d??
@sajadtroll9186
@sajadtroll9186 2 жыл бұрын
watched around 3 videos of events and still can't understand it. any tips ?
@BMoDev
@BMoDev 2 жыл бұрын
Try them yourself! Theyre way easier than it seems. I really struggled when i was first introduced to them
@sajadtroll9186
@sajadtroll9186 2 жыл бұрын
@@BMoDev also I have to say that u're so lovely and I like you🌹
@bren4409
@bren4409 2 жыл бұрын
The colliders aren't working for me. I set the OnTriggerEnter method on my pre-existing player script, but nothing actually happens when I touch my collectible. I'm using Unity 2020.3.37f1. Edit: I found a fix. My player object didn't have a Rigidbody. I don't know why it needs one for the trigger to work, but it works now.
@geoClexE
@geoClexE 2 жыл бұрын
even my player has a rigidbody it didnt collect the collectible
@williamr578
@williamr578 2 жыл бұрын
@@geoClexE Collector script goes on player and add boxcollider2d to player
@thecommentator9043
@thecommentator9043 2 жыл бұрын
@@williamr578 This answer was gold! I was thinking, "Don't we need to attach the collector somewhere?" Thank You!
@kuniokun1st
@kuniokun1st 2 жыл бұрын
@@williamr578 Thank you! After 30 minutes of finding which my fault by missing some code then i saw this.
@geoClexE
@geoClexE 2 жыл бұрын
@@williamr578 u are the boss thank you !!
@nikaman9539
@nikaman9539 2 жыл бұрын
Ive spent 2 hours wondering why I do not get the "collected coin" debug message in console when i realised I never assigned the "collector" to my player.... lmao
@heyreefes
@heyreefes 2 жыл бұрын
Naisu
@dibaterman
@dibaterman 2 жыл бұрын
My soul wants to understand, but my brain is like nope. I get interfaces, I get that you showed 2 ways of implementing them, there's no reason not to use both depending on the use case. For example I tend to make my AI and Player inherit from the same place. I can just put everything on that and define thing there then the player and AI are now damagable, or whatever. But UnityEvents and System Actions... man... The worst part is I need to get my brain to accept whatever the hell is going on here because I want to make an inventory system. The guides I follow tend to use events but I just can't get my brain around invoking them... it's like I sort of know what they do and how they do them but I can't process when or why to use them.
@dibaterman
@dibaterman 2 жыл бұрын
Alright a good way to get this thing to target a specific inventory is to use the collider on the item. Through the itempickup script use a OnTriggerEnter to find the target that entered and find if it has an inventory. To do this, you'll have to delete the OnTriggerEnter check on the player and make a new one on the ItemPickUp. After that I would make the inventory a child of the player and then do a GetComponentInChildren(); So... //Inside of Trigger Enter: var inventory = other.GetComponentInChildren(); if(inventory != null) Collect(inventory); Collect is changed to this: public void Collect(Inventory inventory) { inventory.Add(item); Destroy(gameObject); } Another extension to this may be to add multiple items at once, so say one of those blue gems is actually a stack of 5, or what if that was the case but you could only hold 3 blue gems.
@dibaterman
@dibaterman 2 жыл бұрын
Okay yeah, tested the above and it worked, the only thing is that I get a null reference for the DebugLog on the first check of the dictionary. Not sure why, but commenting it out and the system worked perfect. I can now specify the inventory I want an item to go to on pick up. The downside is the the Events, Delegates, and Interface were mooted by just putting a ontriggerenter check on the pickup (Gem) script. But this is to the point of my original post, see I can do something like this and suddenly script from 3 or 4 different classes (1 interface) are gone. In their place is 3 lines of code that all exist on a pick up script. This is why my brain is like nope, whenever I ask if this is a good time to try using Events.
@wmetz1869
@wmetz1869 2 жыл бұрын
@@dibaterman Thanks for the update.
@dibaterman
@dibaterman 2 жыл бұрын
@@wmetz1869 No problem, a piece of advice is look at Inventory as being 2 different things. 1. Is Game Design the other is Just making a database. If you can make a database fine, now it's time to connect the information in that database to the game in a meaningful way. To do this you create slots that look at the database and makes a clone of that item in your database to the slot. If you have stacks, then make a int for the slot and have the slot grab the int from the database. That sound simple until you ask how do you get the slots? He shows you in this video a very easy way to do this: "Foreach(Transform child in InventoryPanel) is a fantastic way of populating the slots in an inventory.
@isimsizanimator1291
@isimsizanimator1291 8 ай бұрын
yeah my brain not enough for understand
@godzillakingkongvenom
@godzillakingkongvenom 2 жыл бұрын
🥦🎮⚡⚡⚡⚡🙈
@jakeduncan2721
@jakeduncan2721 2 жыл бұрын
First
Flexible LOOT SYSTEM in Unity with Random Drop Rates
13:24
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
A Great Way To Setup POWERUPS In Your Unity Game
13:43
Interacting with Objects and Code in Unity3D
30:03
Jason Weimann (GameDev)
Рет қаралды 31 М.
How to Collect Items (Unity Tutorial)
14:23
Ketra Games
Рет қаралды 64 М.
Unity's New Input System:  The Definitive Guide
32:07
DmanGames
Рет қаралды 34 М.
Rethink Everything with Scriptable Object VARIABLES
15:28
How To Make UIs without frustration | Unity Beginner Tutorial
16:58
This is GameDev
Рет қаралды 36 М.
How to make a Save & Load System in Unity
26:56
Shaped by Rain Studios
Рет қаралды 206 М.
Collect Items in Unity  -  Game Dev Tutorial
17:11
Lost Relic Games
Рет қаралды 29 М.
Getting Started with the Job System in Unity 2019
25:54
Code Monkey
Рет қаралды 184 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.