Character Stats in Unity #1 - Base Implementation

Поделиться
HTML-код
  • Опубликовано: 5 янв 2025

Комментарии • 100

  • @pureay2700
    @pureay2700 4 года назад +9

    i have been teaching myself c# just by looking up stuff when i ran into a problem until i could figure it out. I came here to gets some inspiration on a stat system and left this vid after learning some stuff that i probably wouldn't have learned for a while. thx

    • @chocon2911
      @chocon2911 9 месяцев назад

      can you describe a bit about yourself? I go the way just like you, even the way i make playlist about unity that contains some nice video. I just wanna know do my road of looking for knowledge when ran into problems is a good way. Thank you for reading my small question

    • @pureay2700
      @pureay2700 9 месяцев назад

      @@chocon2911 hey man. Didn't expect to get a reply 3 years later but I'm happy to answer. I'm pretty much a self taught programer for the last 5ish years and have been working on a procedurally generated open world game with stuff like voxel terrain, L system vegetation, and rpgish like power systems similar to ones seen in light novels and manwhas and the like. For any advice I really just recommend jumping into making whatever projects you like and when you run into a problem, Google it 😂, Google will typically have some form of answer even if it's not obvious an you have to twist it. You'll at least be pointed to a topic that you'll have to learn about and do some studying on before jumping back onto your project.
      For example I have a rolling character in my game and was having a lot of difficulty with quaternion logic but after some research on the topic and later finding an old tutorial from catlike coding I was able to make a system that worked for me

  • @lee1davis1
    @lee1davis1 4 года назад +6

    You are a great teacher. I've been using unity for 3 years now and just now found your channel. Sad that all my searches on similar topics did not put you at the top. Great vids. Thanks.

  • @mehmedcavas3069
    @mehmedcavas3069 2 года назад +8

    wow just found your channel. I'm a unity developer for 3 -4 years now and I learned a lot. sad that u stopped making tutorials. you could easily reach thousands of subscribers :)

  • @inferrno52
    @inferrno52 Год назад

    5 years later, this is still helping. Thank you

  • @letsgoPi
    @letsgoPi Год назад

    really insane that i can find content like this on youtube for free, really amazing stuff and can't thank you enough for putting in the time and effort to put these videos out there. i hope you are doing well and thanks again

  • @Alicia0Cramel
    @Alicia0Cramel 4 года назад +2

    I had to rewatch this twice but it made excellent sense afterwards. Tahnk you.

  • @alexhoffmann3002
    @alexhoffmann3002 4 месяца назад

    Thanks for making this excellent tutorial. I really like how your implementation plans for many use cases.

  • @elmer5455
    @elmer5455 2 года назад

    This is the best tutorial series I have watched

  • @skaid6281
    @skaid6281 7 месяцев назад +1

    🎯 Key points for quick navigation:
    00:00 *📊 Stats management in RPG games requires a system for organization beyond simple variable assignments.*
    01:51 *📝 Declaring base values and modifiers lists are crucial for defining character stats.*
    03:49 *🔢 Rounding calculated final values can help avoid float calculation errors, especially with percentage modifiers.*
    06:17 *🔄 Setting a specific order for applying stat modifiers is essential to ensure correct calculations.*
    09:24 *🔄 Implementing a comparison function to sort modifiers based on order is crucial for accurate calculation of final values in character stats.*
    Made with HARPA AI

  • @Astr0B
    @Astr0B 6 лет назад +3

    This is an incredibly well explained example of what I was looking for. Simple and clean code with attention to detail. I’ve been trying to implement a similar,ar system but didn’t know how to handle some edge issues elegantly, you however, solved these issues for me.

    • @Kryzarel
      @Kryzarel  6 лет назад

      Thanks! Glad I could help :D

  • @ashenx2619
    @ashenx2619 4 года назад

    Passively listening to your programming Playlist. Absorbing the little bit of information I can get from just listening, will definitely return to this list of videos again later

  • @NinjaWoobidy
    @NinjaWoobidy 7 лет назад +9

    Awesome tutorial here. I was pleasantly surprised by pacing, the explanation of what you were doing and why, and I really liked the background music. I usually have my own on while watching tutorials anyways. Only thing I would say for improvement is I would give a brief overview of the design before jumping into code. Maybe a picture or something that's like "This system uses a list of modifiers and applies them in a specific order. This ensures...." Etc. Having the design laid out before going into code might help people better remember the stuff covered. Only need to spend like 15 seconds on it. Keep up the good work!

    • @Kryzarel
      @Kryzarel  7 лет назад +2

      Thank you *very much* for your kind words and your feedback. That is an excellent suggestion for sure. I did that better in my first video (about the Genetic Algorithm), and I believe that's part of the reason why it was more successful.
      I'm definitely trying to keep that in mind going forward, but when you have everything so clearly in your head, sometimes it's just easy to forget that the people watching don't :P

  • @josephsmith6924
    @josephsmith6924 6 лет назад +2

    sometimes i feel your going to quick like a sudden burst but i like how well you explain things, i have come away with a lot more knowledge than i came in with thank you for making this video series!. next video time!

  • @carlcarlinn7367
    @carlcarlinn7367 5 лет назад

    I search video like this about weeks... God, thank you. I'll see all of your lessons soon. Very useful!

  • @Sapphiregriffin
    @Sapphiregriffin 5 лет назад +3

    I have learned more from this 1 video about all types of coding than I have from 20 other about "how to make xyz". Seriously amazing, make more vids!

  • @tieyourshoelaces
    @tieyourshoelaces 7 лет назад +6

    Really nice tutorial! I loved the pacing and the small attention to details.
    The only thing I would suggest is making basevalue a property to make it easy to change once the player levels up and I think the isdirty flag will need to be set to true in the setter.
    This was very clear and concise I would love to see more!

    • @Kryzarel
      @Kryzarel  7 лет назад +2

      Thank you so much. I'm super glad you liked it!
      Changing the base value and triggering the recalculation is covered in part 2 - ruclips.net/video/uvOSx5FzDnU/видео.html.
      But I did it slightly differently than what you suggested. I left it as a public variable because I believe it's useful to change both in code and in the Unity inspector (and the inspector doesn't show public properties).

    • @Wolfie5309
      @Wolfie5309 7 лет назад +1

      You could use properties, and use the [SerializeField] property on the variables, and set them to be private. That way they'll be visible in the inspector, and still protected as they should be..

    • @Kryzarel
      @Kryzarel  7 лет назад +3

      WolfDenGaming sure, that would make sense, to set "isDirty" inside the property's setter. In this case, since we want to be able to change the base value from anywhere (code and inspector), that's exactly what a public variable is for. That was my reasoning anyway. In any case, constructive criticism like yours is *always* welcome, though :D

  • @NomadRise
    @NomadRise 5 лет назад +3

    Wow, really impressed with your teaching. It really works for me. Thank you so much for sharing.

  • @FuzzyDunlopification
    @FuzzyDunlopification 3 года назад

    Personally, I believe your video was better than Brackeys. More in depth and easier to follow. Great work!

  • @djpersonalspace2406
    @djpersonalspace2406 2 года назад

    Such a brilliant tutorial wish you were still making videos. Hope you're doing good!

  • @sinistermephisto65
    @sinistermephisto65 6 лет назад +59

    Finally I can make darksouls

  • @Axafekt
    @Axafekt 3 года назад

    this is the most amazing tutorial! I don't know if you still reply to comments but thank you so much.

  • @MQNGameDev
    @MQNGameDev 5 лет назад +20

    I give this tutorial 1010 out of 1010! 0101 stars! It's been difficult to find coding tutorials where the code is elegant. There are way too many tutorials out there, where they just throw the logic together, just to get it to work then go back and fix it. Very S.O.L.I.D-ish tutorial :)

    • @benvella1728
      @benvella1728 2 года назад +1

      It is actually quite SOLID to botch then refactor into the required SOLID principles. I don't want to misrepresent what you said - it's truly valuable for videos like these to be provided in their current format since it's unreasonable for a video to cover the full design / brainstorming process before reaching the final version that gets implemented.
      But I will add for other readers out there that there are talks that warn about immediately trying to capture all the SOLID principles, with companies ending up paralyzed by the sheer overhead that a full SOLID implementation entails when often times one or two **localized** implementations of SOLID principles, achieving very good code flexibility with minimal, and still valuable overhead.

  • @TheLivirus
    @TheLivirus 4 года назад

    I'm not sure I follow everything here, but it seems very legit and professional!

  • @Bokaley
    @Bokaley Год назад

    Glad to find this hidden gem

  • @dwlg
    @dwlg 2 года назад +1

    Loving this Characrter Stat implementation already, this should help me put somthing useful together in my own project for a Unity RPG Stat System, thankyou!

  • @chkn_nugz
    @chkn_nugz 8 месяцев назад

    When I went to make it for myself in godot I. I made the flat and scaling (slightly different to percent) modifies but also added compounding modifiers such as the nested modifier which practically adds to the base modifier (effects scaling modifier) and an compiling modifier which multiplies to the prior modifiers. Calculated: Value = ((BaseValue + TotalNestMod) * TotalScaleMod + TotalFlatMod) * TotalCompilingMod. Multiplication and compiling modifiers are added up before they do the multiplying

  • @cradle_of_chaos
    @cradle_of_chaos 4 года назад +1

    This is excellent work.

  • @taekwon4980
    @taekwon4980 5 лет назад

    You're a god I've been searching this for a while ty!

  • @FavoriteCentaurMoe
    @FavoriteCentaurMoe 5 лет назад

    This is truly a fantastic tutorial, thanks

  • @aFewBitsShort
    @aFewBitsShort 4 года назад

    Amazing tutorial. Learned so much!

  • @morneerasmus1789
    @morneerasmus1789 2 года назад

    Very cool tutorial, thank you :)

  • @Quick-Bull01
    @Quick-Bull01 6 месяцев назад

    You are my hero!

  • @dibaterman
    @dibaterman 2 года назад +1

    I've watched this video maybe 3 times to get my head around some of the methods here.
    I am thinking this solves my eternal question about Unity design, how to create a system without making them or attaching it to the scene via the hierarchy. I'm thinking that doing this basically allows for my scene scripts to kind of use these as assets. They can plug into this script without me having to use a singleton to create an instance of this in the scene itself.
    The logic of the stats and the calculations exists separate from the scene. I think I should move to the next one to see if my thought is right on this.

  • @Veevslav1
    @Veevslav1 6 лет назад

    Awesome video. Looking forward to the others.

  • @GameInventor-iy4gm
    @GameInventor-iy4gm 3 года назад

    Thank you very much, this video solved my problem.

  • @Azurantine81
    @Azurantine81 4 года назад

    Excellent tutorial, subbed

  • @alexyoung2795
    @alexyoung2795 Год назад

    UpdateStatValues doesn't seem to work. It constantly spits out 0 except for on start (inspector values with Character script) and once when item is equipped

  • @greenfox6105
    @greenfox6105 3 года назад +2

    Just wanted to say thanks. I learnt alot from this.
    I do know 3 programmign languages. But not much about C# or Unity. So its quite nice to have examples to learn with. Which i do learn better with :D.
    A big + is the nice slow voice and the actual explaining what does what. It's really helpfull to remember and compare different languages. C# seems quite similar in most things. And unity isn't as scary anymore xD.

  • @RetroGamesHQ
    @RetroGamesHQ 3 года назад

    The link to download the assets in the text version no longer goes to it.

  • @mokalamity888
    @mokalamity888 6 лет назад

    Ola de novo Kryzarel, Optimo video. O ritmo do video é um bocado acelerado para mim. Estive quase duas horas a tentar apanhar as dicas todas que estavas a dar. A verdade é que comecei a pouco tempo a mexer no unity e em c# sem grandes bases de programação. Por isso o ritmo do video até é bom para puchar pela cabeça ahah. Obrigou-me a voltar a tras para ter a certeza que entendia o que estava a acontecer. Optima prática.
    Mas acredito que para pessoas mais experientes que queiram saber como abordar este tipo de problema deve ser o ritmo ideal. Vou ja a correr para o proximo video. Bom trabalho amigo!

    • @Kryzarel
      @Kryzarel  6 лет назад

      Certamente os meus videos não são direcionados para completos principiantes de programação ou Unity, para isso já existem muitos outros milhares de videos com esse público em mente ^^
      No entanto, tento sempre explicar as coisas relativamente detalhadamente, para que qualquer pessoa com algumas bases consiga seguir, mesmo que não ao mesmo ritmo. Pelo teu comentário, penso que fui bem sucedido nesse departamento, pelo menos neste video em particular xD
      De qualquer maneira, estou sempre disponível para responder a quaisquer dúvidas, quer sejam de principiante ou não, quer sejam sobre os tópicos falados nos videos ou outros quaisquer de Unity e programação, tanto por aqui nos comentários do RUclips como no servidor de Discord. Portanto, se alguma vez o video não for esclarecedor, não hesites em perguntar! :D
      Espero que o video tenha sido útil e obrigado pelo teu comentário!

  • @terminatoroffire
    @terminatoroffire Месяц назад

    can use this without percentage? as my system only has additive

  • @alexi2706
    @alexi2706 2 года назад

    will this work with multiple characters that I control since I cannot attach the script to a game object? I am going for something like dos 2

  • @charg1nmalaz0r51
    @charg1nmalaz0r51 2 года назад

    Know this is old but is there a reason why you didnt just call the recalculate method when you add and remove a modifier and store it in a variable called something like modifiedvalue and with the getter just return basevalue + modifiedvalue?

  • @lablabs3726
    @lablabs3726 5 лет назад +1

    what about poison effects or things like that!
    can this also passes these debuffs using ticktacks and also cure it?

  • @radioheadfan7279
    @radioheadfan7279 Год назад

    he is doing magic stuff

  • @saguzarmyst8922
    @saguzarmyst8922 4 года назад

    Can you teach us how to make a training system for attributes? Example: My character hit a monster with Sword. so his sword attribute will increase, making him deal more damage with swords.

  • @nightyonetwothree
    @nightyonetwothree 2 года назад

    would it be better to use structs as modifiers instead of classes?

  • @DeathxStrike18
    @DeathxStrike18 2 года назад

    if you do not add && isDirty to the CalculateModifiedValue StatModifier type if's it will repeat the loop and double your modifier.

  • @magnusm4
    @magnusm4 3 года назад

    Instead of enums.
    Would it be more flexible to make a subclass inherit StatModifier, make the function virtual and make the different ones there.
    Thus you don't have to change the code in the CharacterStat, you don't get locked to just those kind of modifications and you can freely make new ones without having to go into the Stat class and add another enum.
    All you can add along is an order value, base value and current value.
    Say you want something that multiplies by percent, but then you also want one that multiplies by percent based on the base value.
    Then you want one that add the different of the base value and the final value.
    You can end up with a lot of different variations and each would require an enum and change in multiple scripts.
    Which goes against the open close principle.

  • @rryba1356
    @rryba1356 7 лет назад

    Hey, a text version tutorail its pretty great, i think u should add a timer based attributes approach and dependent attributes like in flash verison. Sorting modifiers by type is nice problem solver for percentage attributes, well done. About videos, i cant watch that the most by background music, in tutorials video like this music is just annoying cuz u want to keep focus on code. Very thanks for it, I am goign to modifier system to my purposes and i think i show my aproach on Unity forum ! Keep going on cuz its pretty one level higher tutorial than most there in my opinion :)

    • @Kryzarel
      @Kryzarel  7 лет назад +2

      For timer based modifiers, I prefer *not* including it in this system. I will probably do a tutorial showing how to use and extend this system in more detail, but I'm very happy with its current state. I like that it's extremely simple and does only one single thing: keeps track of modifiers, how long you want to keep them there is up to you, and doesn't belong in the CharacterStat class. But that's just like, my opinion, man, feel free to disagree and I'm *always* open to constructive criticism :)
      I tried to keep the music with a low volume to avoid annoyances and distractions, maybe I should have kept it a bit lower still. I think I did a better job with that on my other videos.
      Other than that, thanks a lot for your kind words and your feedback, I really do appreciate that a lot!

  • @alexyoung2795
    @alexyoung2795 Год назад

    My display number stays 0...

  • @b1uezer
    @b1uezer 6 лет назад +1

    Say you have a stat like "Strength" that used in calculating how much attack damage you do. Then, your character gets a perk that adds 20% of the agility to their Strength stat, and subsequently all calculations dependent on strength (like if they're a rouge or something). Would the setup have to be different than what you have here, or would something like that be handled with another script?

    • @Kryzarel
      @Kryzarel  6 лет назад +2

      That is an excellent question and something I hadn't considered before. At this point I'd suggest making another script that checks for changes in the Agility stat. When a change is detected, add a modifier with value equal to 20% of Agility to Strength, and remove any old modifiers.

    • @b1uezer
      @b1uezer 6 лет назад

      Hey thanks for replying; I'll do it that way then. Really cool of you for creating the tut btw.

  • @shortnr
    @shortnr 6 лет назад

    Edit: Fixed funky math.
    Would it be more efficient to loop through StatModifiers and add the modifier to either a fixed or scalar float, then perform the calculation all at once?
    i.e.:
    Mod1 - 10 (fixed)
    Mod2 - 0.10 (perc)
    Mod3 - 20 (fixed)
    Mod4 - 0.20 (perc)
    fixed = mod1 + mod3 = 30 (fixed)
    perc = mod2 + mod4 = 0.30 (perc)
    finalValue = (baseValue + fixed) * (1 + perc)
    With your method, you need to loop through your StatModifiers at least twice (your sort can take more than the size of your array). With the method above, you loop through only once.

    • @Kryzarel
      @Kryzarel  6 лет назад +1

      That is very true and a great observation. However, in the next video we change this to allow custom order of application for each individual modifier.
      So you might need to do:
      finalValue = ((baseValue + mod1) * (1 + mod2) + mod3) * (1 + mod4))
      I don't believe there's another way to do that without the for loop.
      I also like the side effect of the StatModifiers list being sorted in the order that the modifiers are actually being applied in the calculations. But that's just a convenient extra :p

  • @JayXan
    @JayXan 5 лет назад

    I'm confused. So I just wrote out that void function at the very beginning, and then all the sudden it fades like that it doesnt need to be in there, but you say lets also add a constructor. Am I supposed to erase that function, and continue writing or not? Where did that code go.

    • @Wisse37
      @Wisse37 5 лет назад +1

      he used that as an example to explain what readonly does, so you can just comment or delete it.

  • @pureay2700
    @pureay2700 4 года назад

    also hope you upload again

  • @sainttymez5146
    @sainttymez5146 6 лет назад +1

    What happens around 2:20 and 2:21? Did you just delete that part?

    • @Kryzarel
      @Kryzarel  6 лет назад +3

      Yes. Those were just examples to illustrate my point, not part of the implementation.

    • @sainttymez5146
      @sainttymez5146 6 лет назад +1

      Awesome. Thank you. Just got a bit confused.

  • @_danny_idk
    @_danny_idk 4 года назад

    2:21 you wrote some code lines and then you deleted them? Why?

    • @timmytimmy9771
      @timmytimmy9771 4 года назад

      This was because he was explaining how the "readonly" keyword protects the variable (list) from being tempered with.
      Those lines of code was an example on how the list can still be used but will not accidentally break due to someone overriding it.

    • @_danny_idk
      @_danny_idk 4 года назад +1

      @@timmytimmy9771 thx

  • @plyrni3
    @plyrni3 2 года назад

    Your account name on visual is "tg darkfire". Which sound weird for the french i am x)
    In French, your account name as a different meaning : "shut up darkfire"
    We use the abreviation "tg" to say "Ta gueule" which mean "Shut up"

  • @encel4dus
    @encel4dus 3 года назад

    good vid

  • @zephysm4920
    @zephysm4920 4 года назад

    Sir, Do you have any idea how fast you were coding back there?

    • @Kryzarel
      @Kryzarel  4 года назад +4

      I'm sorry officer, here's my license and registration.

  • @thedj_mo
    @thedj_mo 5 лет назад +2

    Sometimes it was too fast

  • @Mr_Wiley
    @Mr_Wiley 4 года назад

    I don't know if you're still reading comments!
    First question:
    Are you still programming? Your vids ended!
    Second question (for anyone as well):
    Do you still think this is how you would code your stat system? Any changes you might make? Just curious!

  • @fumein5588
    @fumein5588 3 года назад +1

    Video is nice you share useful informations but the fact that you didn't showcase how any of this code works in unity made it not understandable and hard to follow. We are just creating functions after functions.

  • @Jeremy_Davis
    @Jeremy_Davis 6 лет назад +5

    Jesus Christ you are fast paced, good info though

    • @newf_gg1230
      @newf_gg1230 5 лет назад +2

      I didn't see "beginner" in the title or description so not sure why you thought it would be slow.

  • @Grempington
    @Grempington 6 лет назад +1

    It really pains me to see a sort after every list modification, it'd be much better to use a heap instead of a list in such a case.
    Edit: Not sure what I was thinking here, minheap/maxheap isn't a good data structure for this. Disregard this comment

    • @Kryzarel
      @Kryzarel  6 лет назад +3

      Great insight. I gotta be honest here, I'm not very familiar with heaps, I've already learned something new. Thank you for your comment!

    • @charg1nmalaz0r51
      @charg1nmalaz0r51 2 года назад

      what do you mean by this? im googling around and when it comes to this problem people just use lists if the items can be duplicates and sort as this guy did or they use sorted lists if the values arent possibly duplicates. And anything related to the word heap talks about memory allocation.

    • @Grempington
      @Grempington 2 года назад

      @@charg1nmalaz0r51 minheap / maxheap I guess is what I meant, but looking at this vid again I can't see how it can be used here. It's a data structure where getting the min element at any given time is O(1) but modifying (popping, or pushing to the heap) is O(logn).
      It sounds very nice and all, but the most important thing here is that modifications don't occur every frame, while iteration does occur every frame. Iterating in actual sorted order over the min heap would be O(nlogn) while iterating over this sorted array is O(n), so it's actually pretty bad here.
      I think I was thinking about a very specific usecase in my game back then where a minheap alternative was actually viable? For example I had to modify the heap almost same order of magnitude per frame as I had to iterate over it?
      This is a stupid comment and I might actually delete it soon as it's not relevant for this usecase, sorry for confusing you unnecessarily

  • @MohanABK
    @MohanABK 3 года назад

    10:17 "I will be replying to every single comment". :(

  • @ohwhatworld5851
    @ohwhatworld5851 4 года назад +1

    Sweet Jesus I'm confused. I am sure you are a very good teacher, I am just totally new to C sharp..... I shouldn't be watching this haha.

  • @transtaco3073
    @transtaco3073 4 года назад +2

    Its alright, but if too confusing. Like can you atleast next time make it so you can give us the whole script instead of KEEP ADDING THIS THEN THIS... Then minus that then this.

    • @kriegnes
      @kriegnes 4 года назад +2

      yeah i wish videos would have a pause function

    • @charg1nmalaz0r51
      @charg1nmalaz0r51 2 года назад

      Its more confusing if you have the wole script. Doing it like this shows the though process in building up the system. If you are just given it one you are tempted to not bother figuring it out yourself and two there may be steps that you miss because of the thinking behind each step.

  • @aFewBitsShort
    @aFewBitsShort 4 года назад +2

    Amazing tutorial. I learned so much!