Using Attributes to Manage Data in Unity

  Рет қаралды 46,714

Game Dev Guide

Game Dev Guide

Күн бұрын

Пікірлер: 107
@yoimokacc
@yoimokacc 3 жыл бұрын
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 3 жыл бұрын
You make programming look so easy, it's impressive, hope I get there eventually!
@小鳥ちゃん
@小鳥ちゃん 3 жыл бұрын
wanna be friends?
@xdCloudxd1996
@xdCloudxd1996 3 жыл бұрын
@@小鳥ちゃん yeah sure ^^ it's just, sometimes you don't really know where to start ':D
@小鳥ちゃん
@小鳥ちゃん 3 жыл бұрын
@@xdCloudxd1996 nice uwu then, I guess it would make sense to move to discord or something xd
@xdCloudxd1996
@xdCloudxd1996 3 жыл бұрын
@@小鳥ちゃん I sent you an invite on steam
@benj2535
@benj2535 2 жыл бұрын
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.
@kennypu
@kennypu 3 жыл бұрын
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 3 жыл бұрын
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.
@TheOriginalFish
@TheOriginalFish 3 жыл бұрын
Your in depth content is exactly the thing I need to up my Unity knowledge further, thanks matt and keep it up!
@3enny3oy
@3enny3oy 2 жыл бұрын
Thanks for this! The first tutorial on custom attributes in Unity that hasn't sent me to sleep 😂 you're a legend
@SanderDecleer
@SanderDecleer 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 3 жыл бұрын
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 3 жыл бұрын
@@harshmudhar96 Wow, thanks for the TypeCache pointer
@darkenaxe
@darkenaxe 3 жыл бұрын
@@harshmudhar96 Do you mean that you are packing your "reflection" related code into extension methods in order to keep things more clear ?
@harshmudhar96
@harshmudhar96 3 жыл бұрын
@@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 3 жыл бұрын
@@harshmudhar96 Oh ok, it indeed seems kind of flexible, thank you for taking the time to share this :)
@krisztianszendrodi7057
@krisztianszendrodi7057 3 жыл бұрын
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!
@arksizy1729
@arksizy1729 3 жыл бұрын
Now this is quality content, glad I found this channel. Best of wishes
@_denzy_6310
@_denzy_6310 3 жыл бұрын
When you spend more time designing the tools for the game than the actual game lol
@TheRmbomo
@TheRmbomo 3 жыл бұрын
Always sharpening the axe.
@behnamrasooli8801
@behnamrasooli8801 3 жыл бұрын
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 3 жыл бұрын
I spend more time in tools. Tools can be used so often and make development workflow easier.
@behnamrasooli8801
@behnamrasooli8801 3 жыл бұрын
@Гоша Ватюнга 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 3 жыл бұрын
@@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.
@tommy031088
@tommy031088 3 жыл бұрын
Dude, this is a fantastic video with both clear concept and explanation! Your channel really deserves more attention.
@MaZyYTube
@MaZyYTube 3 жыл бұрын
I like that. I most time work on stuffs like that more than game development. Reflections are really cool. Worked very often with that.
@Pedro_Marangon
@Pedro_Marangon 2 жыл бұрын
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)
@Hymnal27
@Hymnal27 3 жыл бұрын
I literally ran into this today and thought "there must be a better way". Thanks!
@gammacreeper1234
@gammacreeper1234 3 жыл бұрын
Just found your Channel 2 Weeks ago and i think you are my new Brackeys :D. Great Videos :)
@ChiliDev
@ChiliDev 3 жыл бұрын
Very useful video dude loving the concept and it will really ease the load for the designers in making content
@enriquemorenotent
@enriquemorenotent 3 жыл бұрын
Wow, this is really advanced. I gotta admit I was unable to follow it, even pausing the video :/
@burstofsanity
@burstofsanity 3 жыл бұрын
Same here and I've been programming to some degree for over 20 years … damn I'm old.
@小鳥ちゃん
@小鳥ちゃん 3 жыл бұрын
@@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 3 жыл бұрын
@@小鳥ちゃん 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.
@小鳥ちゃん
@小鳥ちゃん 3 жыл бұрын
@@burstofsanity well, I'm used to use reflection for something like modules or marking routes in the web dev
@enriquemorenotent
@enriquemorenotent 3 жыл бұрын
@@lee1davis1 Who is Matt?
@bluedev6304
@bluedev6304 2 жыл бұрын
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
@Mimas74
@Mimas74 2 жыл бұрын
This is amazing! Thank you for your time to create this video.
@bobbymcbobface
@bobbymcbobface 3 жыл бұрын
yay! new game dev guide vid - good as always :)
@RandomProduct
@RandomProduct 3 жыл бұрын
Pretty cool to see my name in the credits! Keep up the good work dude! :)
@noodle-eater
@noodle-eater 3 жыл бұрын
Awesome, thanks dude. Perfect idea for my localization
@MarekNijaki
@MarekNijaki 3 жыл бұрын
Awesome video
@ThatAcc
@ThatAcc 3 жыл бұрын
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.
@KoshYoutube
@KoshYoutube 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
@slagtp8603
@slagtp8603 3 жыл бұрын
I would love to see logical box representation of all classes in single frame.
@Pedro5antos_
@Pedro5antos_ 3 жыл бұрын
Awesome, awesome content and explanation! Keep it up
@LaCreArthur
@LaCreArthur 2 жыл бұрын
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...
@liualex32
@liualex32 3 жыл бұрын
Great work, Great help.
@ffurkan04
@ffurkan04 3 жыл бұрын
Nice thanks I use
@ruchirraj5300
@ruchirraj5300 3 жыл бұрын
I've been searching for this for a long time 😀
@yhd4711499
@yhd4711499 3 жыл бұрын
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
@monsume123
@monsume123 3 жыл бұрын
Amazing tutorial. Thanks ! Is this available somewhere, would like to browse through the code some more?
@ludologian
@ludologian 3 жыл бұрын
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
@legends389
@legends389 3 жыл бұрын
Awesome Video =D
@DePistolero
@DePistolero 3 жыл бұрын
Thank you so much!!!
@mrx10001
@mrx10001 3 жыл бұрын
Do you ever share the repos for your videos? Would be really appreciated.
@twoloopgames
@twoloopgames 2 жыл бұрын
What software do you use to edit?
@gregoryfenn1462
@gregoryfenn1462 Жыл бұрын
At 2:45, what even is an assembly? How can you iterate through them?
@crash1998100
@crash1998100 3 жыл бұрын
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.
@Mika-di5nz
@Mika-di5nz 3 жыл бұрын
Nice
@ThomasChen-ur2gt
@ThomasChen-ur2gt 3 жыл бұрын
Can I somehow get your project file? I'm kind of lost after watching the video, and I really want to fully understand it.
@herohiralal3255
@herohiralal3255 3 жыл бұрын
Can you do a video on the behaviour nodes thing that you use?
@uncleg1214
@uncleg1214 3 жыл бұрын
Can you please make a tutorial for creating a node graph editor extension using reflection and serialized properties please
@Caslte371
@Caslte371 3 жыл бұрын
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?
@floriangr7888
@floriangr7888 3 жыл бұрын
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
@teemuleppa3347
@teemuleppa3347 3 жыл бұрын
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 2 жыл бұрын
I would use these methods for game code, but editor code I don't see too much of an issue.
@chrisskyr623
@chrisskyr623 2 жыл бұрын
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 2 жыл бұрын
You probably need to add the System.Collections.Generic namespace
@RandomProduct
@RandomProduct 3 жыл бұрын
Hellllll yeah
@ananttiwari1337
@ananttiwari1337 3 жыл бұрын
Patreon?
@RandomProduct
@RandomProduct 3 жыл бұрын
@@ananttiwari1337 yup! Would recommend.
@ruchirraj5300
@ruchirraj5300 3 жыл бұрын
What was the node editor framework you were using?
@arthurmartins1511
@arthurmartins1511 3 жыл бұрын
he made it himself
@vAscA187
@vAscA187 3 жыл бұрын
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 3 жыл бұрын
Yes. You can save it with Unity's serialiser too if you first make a class out of it.
@vAscA187
@vAscA187 3 жыл бұрын
@@harshmudhar96 tnx bud, allready did that but the game wasn, t at testable point and i wanted to double check
@nomadcrossfire
@nomadcrossfire 3 жыл бұрын
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 3 жыл бұрын
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.
@ThomasChen-ur2gt
@ThomasChen-ur2gt 3 жыл бұрын
I normally double the play speed, but I have to slow it done for this
@milkgang6331
@milkgang6331 3 жыл бұрын
Cool. Nice teaching(easy to understand)
@Tiranice
@Tiranice 3 жыл бұрын
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 3 жыл бұрын
yeah that makes sense since you only wanna update those values at runtime
@Tiranice
@Tiranice 3 жыл бұрын
@@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 3 жыл бұрын
@@Tiranice I thought you meant whenever you pressed the button
@willpetillo1189
@willpetillo1189 3 жыл бұрын
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 3 жыл бұрын
Attributes add meta data to your class definitions in a way you can't normally do.
@harshmudhar96
@harshmudhar96 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
End of the day, it's a simplified problem for demonstration porpoises.
@minecraftermad
@minecraftermad 3 жыл бұрын
To avoid this issue i basically made a visual scripting language in my project...
@harshmudhar96
@harshmudhar96 3 жыл бұрын
Delegate.CreateDelegate is my god.
@Kenbomp
@Kenbomp Жыл бұрын
Seems to violate encapsulation but ok.
@jayshippey6772
@jayshippey6772 2 жыл бұрын
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
@toastyshrimp1882
@toastyshrimp1882 Жыл бұрын
this isn't for beginners. This channel isn't for you.
@kakarotsan3030
@kakarotsan3030 2 жыл бұрын
Holy over-engineering, Batman. I don't think reflection is great idea for performance either.
@RimmCriolle
@RimmCriolle Жыл бұрын
this video is way too fast for me
@tomtomkowski7653
@tomtomkowski7653 3 жыл бұрын
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 3 жыл бұрын
Nice
Getting Started with Compute Shaders in Unity
14:03
Game Dev Guide
Рет қаралды 198 М.
Speed Up Compile Times in Unity with Assembly Definitions
9:54
Game Dev Guide
Рет қаралды 90 М.
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 2,5 МЛН
هذه الحلوى قد تقتلني 😱🍬
00:22
Cool Tool SHORTS Arabic
Рет қаралды 99 МЛН
Пришёл к другу на ночёвку 😂
01:00
Cadrol&Fatich
Рет қаралды 7 МЛН
5 Things You Can Do To Make Games Like A Pro In Unity
9:45
Game Dev Guide
Рет қаралды 115 М.
Designing a Loading Screen in Unity
11:57
Game Dev Guide
Рет қаралды 180 М.
SAVE & LOAD SYSTEM in Unity
18:20
Brackeys
Рет қаралды 1,1 МЛН
Why Your Game Should Be Using PlasticSCM For Version Control
9:35
Game Dev Guide
Рет қаралды 44 М.
Unity async / await: Coroutine's Hot Sister [C# & Unity]
16:18
How To Get A Better Grid Layout in Unity
12:04
Game Dev Guide
Рет қаралды 208 М.
I'm Working On Something New...
6:03
Game Dev Guide
Рет қаралды 14 М.
The 6 Design Patterns game devs need?
24:20
Jason Weimann
Рет қаралды 367 М.
Building Runtime UI with UI Toolkit In Unity
21:35
Game Dev Guide
Рет қаралды 41 М.
Designing A Responsive Tooltip System in Unity
9:45
Game Dev Guide
Рет қаралды 88 М.