Using Attributes to Manage Data in Unity

Sdílet
Vložit
  • čas přidán 28. 08. 2024

Komentáře • 107

  • @yoimokacc
    @yoimokacc Před 3 lety +24

    This is something I've been looking for ages. To make a dialogue system that can reference properties and check what they are

  • @xdCloudxd1996
    @xdCloudxd1996 Před 3 lety +12

    You make programming look so easy, it's impressive, hope I get there eventually!

    • @小鳥ちゃん
      @小鳥ちゃん Před 3 lety +1

      wanna be friends?

    • @xdCloudxd1996
      @xdCloudxd1996 Před 3 lety

      @@小鳥ちゃん yeah sure ^^
      it's just, sometimes you don't really know where to start ':D

    • @小鳥ちゃん
      @小鳥ちゃん Před 3 lety

      @@xdCloudxd1996 nice uwu then, I guess it would make sense to move to discord or something xd

    • @xdCloudxd1996
      @xdCloudxd1996 Před 3 lety

      @@小鳥ちゃん I sent you an invite on steam

  • @benj2535
    @benj2535 Před 2 lety +1

    I did this a while ago and forgot to leave a comment but combining this with your cheat console tutorial has been so useful!
    Thank you so much!
    Your videos has been so useful for me and I feel stupid about not knowing about some of this stuff before.

  • @3enny3oy
    @3enny3oy Před 2 lety

    Thanks for this! The first tutorial on custom attributes in Unity that hasn't sent me to sleep 😂 you're a legend

  • @_denzy_6310
    @_denzy_6310 Před 3 lety +75

    When you spend more time designing the tools for the game than the actual game lol

    • @TheRmbomo
      @TheRmbomo Před 3 lety +12

      Always sharpening the axe.

    • @behnamrasooli8801
      @behnamrasooli8801 Před 3 lety +6

      I guess it's because making tools are easier than making games. Some people do this to make themselves feel productive :) No offence to this channel though. I love this channel.

    • @MaZyYTube
      @MaZyYTube Před 3 lety +2

      I spend more time in tools. Tools can be used so often and make development workflow easier.

    • @behnamrasooli8801
      @behnamrasooli8801 Před 3 lety +2

      @Гоша Ватюнга The reason I say making tools is easier is that a tool doesn't need to be fun. This 'fun factor' makes developing games harder because it often requires radical changes in the codebase architecture. When making tools, we relatively know more about the end product, so we can plan ahead. I'm not say making tools is easy, but it's easier.

    • @harshmudhar96
      @harshmudhar96 Před 3 lety +2

      @@behnamrasooli8801 The one thing that makes or breaks a game engine is tooling. It's not how state of the art the rendering pipeline is, how many systems are prepackaged into the engine, how advanced in built AI is. It's tooling, and it takes a lot of UX knowledge and coding chops to make good tools.

  • @kennypu
    @kennypu Před 3 lety +2

    Nice, I used to use Enums for a much simpler version of this, but being able to tag attributes to automatically create a list is much more helpful in the long run (although more to code).

  • @thebebinator
    @thebebinator Před 3 lety +4

    Awesome video. I'm definitely going to use this in my work. Some constructive feedback: I would say in the future you could reduce your fastforward speed by about 50%. it was a bit too fast to follow what was going on without heavy use of the pause/rewind buttons. I would just slow everything down a little bit to make it a bit easier on the viewers. Also pausing for a second between the voiceover sentences would help digest the information as well.

  • @SanderDecleer
    @SanderDecleer Před 3 lety +3

    I am always kind of put back by the complexity and verbosity of using reflection. I hope we can all agree that this kind of code is not very readable at first glance.
    You have convinced me to push through and make more use of it however. It is a potent tool with many possible applications.
    Thank you for giving such a clear example.

    • @harshmudhar96
      @harshmudhar96 Před 3 lety +1

      Two words: extension methods.
      Another two words: TypeCache class.
      It is rather tiresome at first glance, but gets easier over time. Still, deep reflection will always feel, for the lack of a better work, fucky.

    • @SanderDecleer
      @SanderDecleer Před 3 lety +1

      @@harshmudhar96 Wow, thanks for the TypeCache pointer

    • @darkenaxe
      @darkenaxe Před 3 lety

      @@harshmudhar96 Do you mean that you are packing your "reflection" related code into extension methods in order to keep things more clear ?

    • @harshmudhar96
      @harshmudhar96 Před 3 lety +1

      @@darkenaxe Basically, I have two classes: ReflectionUtils and TypeExtensions. Type extensions has the common extension methods, like GetMemberValue (getting value from fieldinfo/propertyinfo/method). Every reflection based operation I have to do, usually ends up as a pair of Static Method + Private Static Dictionary. Over time, I end up re-using these operations, which saves time.

    • @darkenaxe
      @darkenaxe Před 3 lety +1

      @@harshmudhar96 Oh ok, it indeed seems kind of flexible, thank you for taking the time to share this :)

  • @tommy031088
    @tommy031088 Před 3 lety +1

    Dude, this is a fantastic video with both clear concept and explanation! Your channel really deserves more attention.

  • @arksizy1729
    @arksizy1729 Před 3 lety +2

    Now this is quality content, glad I found this channel. Best of wishes

  • @TheOriginalFish
    @TheOriginalFish Před 3 lety +1

    Your in depth content is exactly the thing I need to up my Unity knowledge further, thanks matt and keep it up!

  • @MaZyYTube
    @MaZyYTube Před 3 lety

    I like that. I most time work on stuffs like that more than game development.
    Reflections are really cool. Worked very often with that.

  • @krisztianszendrodi7057

    This is really cool! I use and create this kind of tools all the time, but I did not see anyone covering it on youtube, great job!

  • @enriquemorenotent
    @enriquemorenotent Před 3 lety +43

    Wow, this is really advanced. I gotta admit I was unable to follow it, even pausing the video :/

    • @burstofsanity
      @burstofsanity Před 3 lety +2

      Same here and I've been programming to some degree for over 20 years … damn I'm old.

    • @小鳥ちゃん
      @小鳥ちゃん Před 3 lety

      @@burstofsanity really? :o were you using c# for a long time? because im using it for like 6 years and can't live without custom attributes basically

    • @burstofsanity
      @burstofsanity Před 3 lety

      @@小鳥ちゃん No, I started using c# about 3 years ago through Unity but no formal training in it. Most of my time was in C++.
      Since my earlier comment I watched some other videos on the subject because I was curious and rewatched this one. I don't see the way it's explained here any easier to follow though. And I find the example use case for text replacement clunky.

    • @小鳥ちゃん
      @小鳥ちゃん Před 3 lety

      @@burstofsanity well, I'm used to use reflection for something like modules or marking routes in the web dev

    • @enriquemorenotent
      @enriquemorenotent Před 3 lety

      @@lee1davis1 Who is Matt?

  • @Hymnal27
    @Hymnal27 Před 3 lety

    I literally ran into this today and thought "there must be a better way". Thanks!

  • @gammacreeper1234
    @gammacreeper1234 Před 3 lety

    Just found your Channel 2 Weeks ago and i think you are my new Brackeys :D. Great Videos :)

  • @ThatAcc
    @ThatAcc Před 3 lety

    Did I say that i love you deeply before? I think I did, but just in case: I love you and all the videos you upload, thank you.

  • @Pedro_Marangon
    @Pedro_Marangon Před 2 lety

    Awesome video! I can see this being applied to that Debug Cheat video you did, making it easier to add commands simply by adding an attribute to a method (similar to how the Quantum Console asset works)

  • @bluedev6304
    @bluedev6304 Před 2 lety +4

    Can the process of getting attributes from reflection get faster? Coz i wanna access them at runtime but it takes like 5 seconds for the reflection task to finish. and i also noticed that the current appdomain gives 91 assemblies but only 2 of them are actually created by me and i can edit them all the others are unity's pre compiled dlls or system dlls which are useless to me

  • @RandomProduct
    @RandomProduct Před 3 lety

    Pretty cool to see my name in the credits! Keep up the good work dude! :)

  • @Mimas74
    @Mimas74 Před 2 lety

    This is amazing! Thank you for your time to create this video.

  • @ChiliDev
    @ChiliDev Před 3 lety

    Very useful video dude
    loving the concept and it will really ease the load for the designers in making content

  • @noodle-eater
    @noodle-eater Před 3 lety

    Awesome, thanks dude. Perfect idea for my localization

  • @bobbymcbobface
    @bobbymcbobface Před 3 lety +1

    yay! new game dev guide vid - good as always :)

  • @MarekNijaki
    @MarekNijaki Před 3 lety

    Awesome video

  • @Pedro5antos_
    @Pedro5antos_ Před 3 lety

    Awesome, awesome content and explanation! Keep it up

  • @liualex32
    @liualex32 Před 3 lety

    Great work, Great help.

  • @ffurkan04
    @ffurkan04 Před 3 lety +1

    Nice thanks I use

  • @slagtp8603
    @slagtp8603 Před 3 lety +1

    I would love to see logical box representation of all classes in single frame.

  • @KoshYoutube
    @KoshYoutube Před 3 lety +3

    I think it is more readable to assign values to tags in the text. So you can say {PLAYER_AGE} refers to the age value of the player. {0}, {1}, etc, do not really make sense too much for the person editing the text

  • @LaCreArthur
    @LaCreArthur Před 2 lety

    Awesome video thank you ! Never had the courage to dig into this subject and finally did so very happy !
    Is there a way for the code to be more performant though ? The all assemblies lookup is very long even for almost empty project...
    Every access to a ExposedValueText takes several seconds...

  • @ruchirraj5300
    @ruchirraj5300 Před 3 lety +2

    I've been searching for this for a long time 😀

  • @monsume123
    @monsume123 Před 3 lety

    Amazing tutorial. Thanks ! Is this available somewhere, would like to browse through the code some more?

  • @ludologian
    @ludologian Před 3 lety +1

    Reflection and dynamic aren't allowed on ios , ( sure the editor is allowed) the final compiled won't have any editor related code .
    I might need this in the future thanks for sharing

  • @DePistolero
    @DePistolero Před 3 lety

    Thank you so much!!!

  • @gregoryfenn1462
    @gregoryfenn1462 Před rokem

    At 2:45, what even is an assembly? How can you iterate through them?

  • @uncleg1214
    @uncleg1214 Před 3 lety

    Can you please make a tutorial for creating a node graph editor extension using reflection and serialized properties please

  • @Caslte371
    @Caslte371 Před 3 lety

    That thing, where you get access to assemblies. Can I add to all data, that need to be persisted an interface (something like "savable") and get through them all?

  • @yhd4711499
    @yhd4711499 Před 3 lety

    like it so much
    whats the name of the graphic editing tool (looks like an graphic coding tool) at the begining? it looks really cool

  • @twoloopgames
    @twoloopgames Před 2 lety

    What software do you use to edit?

  • @ThomasChen-ur2gt
    @ThomasChen-ur2gt Před 3 lety +1

    Can I somehow get your project file? I'm kind of lost after watching the video, and I really want to fully understand it.

  • @Mika-di5nz
    @Mika-di5nz Před 3 lety +1

    Nice

  • @crash1998100
    @crash1998100 Před 3 lety

    I tend to use attributes and reflections as a last resort because it takes a lot of work and code for pretty basic results. Feels like there should be a simpler way.

  • @floriangr7888
    @floriangr7888 Před 3 lety

    Hi, i wanted to extend your code and include prefabs in the list but I got stuck with the selection part
    Since prefabs are instances of the same class i cant differentiate the FieldInfo with a simple string
    So when i select a exposed Property of my Prefabs it just takes the first FieldInfo with the same name
    i would have to change the ExposedValueSelector to something else then a string or extend it somehow

  • @herohiralal3255
    @herohiralal3255 Před 3 lety

    Can you do a video on the behaviour nodes thing that you use?

  • @mrx10001
    @mrx10001 Před 3 lety

    Do you ever share the repos for your videos? Would be really appreciated.

  • @chrisskyr623
    @chrisskyr623 Před 2 lety

    Plas help me I am getting a error at 3:17 with the line
    if(member.CustomAttributes.ToArray.Lenght > 0)
    it say that ToArray() does not exist
    I am using unity 2021.2.9f1

    • @Pedro_Marangon
      @Pedro_Marangon Před 2 lety +1

      You probably need to add the System.Collections.Generic namespace

  • @ThomasChen-ur2gt
    @ThomasChen-ur2gt Před 3 lety

    I normally double the play speed, but I have to slow it done for this

  • @legends389
    @legends389 Před 3 lety

    Awesome Video =D

  • @teemuleppa3347
    @teemuleppa3347 Před 3 lety

    i've heard that using reflections are inefficent performancewise since doing those things at runtime gives a performance hit....what's your take on this?

    • @AM-vr4qy
      @AM-vr4qy Před 2 lety

      I would use these methods for game code, but editor code I don't see too much of an issue.

  • @nomadcrossfire
    @nomadcrossfire Před 3 lety

    Any idea how to make a "hook" style attribute like the unet syncVar so that it'll cause a method to run whenever the value changes? I know how to do it via properties, but was curious about an attribute based solution.

    • @harshmudhar96
      @harshmudhar96 Před 3 lety

      In an ideal world, we'd have proxy objects easily available. The job of a proxy is to transparently intercepts, in this case, get/set operations. So as a programmer all you did was declare a normal auto property with an attribute, but when it runs, it automatically gets replaced by a proxy that intercepts (Prop.Set) and does something between the assignment and the actual setting of the value. (In this case it internally notifies some service that the view is dirty now and needs to be synced).
      You could achieve the same thing by patching the IL after compilation.
      I'm actually not sure how SyncVar does it.

  • @milkgang6331
    @milkgang6331 Před 3 lety

    Cool. Nice teaching(easy to understand)

  • @ruchirraj5300
    @ruchirraj5300 Před 3 lety

    What was the node editor framework you were using?

  • @vAscA187
    @vAscA187 Před 3 lety +1

    I don't even know how to ask...
    Can int[ ] [ ] or int[ , ] be saved in a binary formatter, serializable, data container method (insert coding words here)? :)))

    • @harshmudhar96
      @harshmudhar96 Před 3 lety +1

      Yes. You can save it with Unity's serialiser too if you first make a class out of it.

    • @vAscA187
      @vAscA187 Před 3 lety

      @@harshmudhar96 tnx bud, allready did that but the game wasn, t at testable point and i wanted to double check

  • @Tiranice
    @Tiranice Před 3 lety

    5:04 And throws a null reference exception when the game isn't running because GameManager.instance is initialized at runtime, unless I've missed something.

    • @ZiplawDev
      @ZiplawDev Před 3 lety

      yeah that makes sense since you only wanna update those values at runtime

    • @Tiranice
      @Tiranice Před 3 lety

      @@ZiplawDev But OnGUI() is called whenever the editor is interacted with, so will spam the console with errors. Fixing that would just require checking Application.isPlaying before doing the reflection.

    • @ZiplawDev
      @ZiplawDev Před 3 lety

      @@Tiranice I thought you meant whenever you pressed the button

  • @willpetillo1189
    @willpetillo1189 Před 3 lety +2

    Maybe I am not advanced enough for this content yet, but I am not seeing the value-add here over, say, giving public variables meaningful names and editing their content in ScriptableObjects.

    • @harshmudhar96
      @harshmudhar96 Před 3 lety

      Attributes add meta data to your class definitions in a way you can't normally do.

    • @harshmudhar96
      @harshmudhar96 Před 3 lety

      Guide showed a very simplified example for demonstration purposes. Not to mention, attributes are a part of the type system, and thus can be programmed against with static guarantees. Naming is a convention.

    • @harshmudhar96
      @harshmudhar96 Před 3 lety +1

      Finally, making editor tools is basically the editor version of static type checking. You can misspell {D_HOME}, but it's much more difficult to select Locations/Home from a drop down. Let's say you have a new team member that doesn't know your 100s of content-specific variables. A tool for exploring variables goes a long way,

    • @willpetillo1189
      @willpetillo1189 Před 3 lety +1

      Lol, if you are going to troll, show some self-respect and put at least a little effort into it!
      Thanks for the explanation Harshdeep. I still don't follow, again in terms of the real-world problem being solved. More specifically, the first half where he creates a property drawer instead of just using [SerializeField] variableName in the script directly (the advantage of selecting variables from a dropdown over typing them in is clear enough).
      Is it being able to reference the same variables from multiple scripts with no chance of misspelling? If so, that's incredibly trivial with ScriptableObjects. If this adds in being able to allow those scripts pick and choose in the editor which variables it has access to...again trivial with ScriptableObjects. If this also adds being able to avoid having to define which variables go together in a centralized way or being able to change what variables a script uses quickly, that's kinda cool I guess...

    • @harshmudhar96
      @harshmudhar96 Před 3 lety

      End of the day, it's a simplified problem for demonstration porpoises.

  • @RandomProduct
    @RandomProduct Před 3 lety

    Hellllll yeah

  • @Kenbomp
    @Kenbomp Před rokem

    Seems to violate encapsulation but ok.

  • @minecraftermad
    @minecraftermad Před 3 lety

    To avoid this issue i basically made a visual scripting language in my project...

  • @harshmudhar96
    @harshmudhar96 Před 3 lety

    Delegate.CreateDelegate is my god.

  • @jayshippey6772
    @jayshippey6772 Před 2 lety +1

    Jeez this video is impossible to follow. There's so much extra stuff he does not mention that is required and so much of the confusion comes from how zoomed in on things he is all the time. There's stuff offscreen that's needed for a lot of this stuff

  • @kakarotsan3030
    @kakarotsan3030 Před 2 lety

    Holy over-engineering, Batman.
    I don't think reflection is great idea for performance either.

  • @RimmCriolle
    @RimmCriolle Před rokem

    this video is way too fast for me

  • @tomtomkowski7653
    @tomtomkowski7653 Před 3 lety

    Because you showing something fast it doesn't make it looks more advanced.
    Slow down man, hard to follow even with pausing the video.

  • @SaiponathGames
    @SaiponathGames Před 3 lety

    Nice