Creating Objects in Unity3D using the Factory Pattern

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.ค. 2024
  • Check out the Course: bit.ly/3i7lLtH
    -------
    I'm giving away another Oculus Rift - unity3d.college/giveaway
    The factory pattern is a great way to create your objects. You can use it to defer creation of objects when you don't know at compile time what you'll need. In this video, I'll show you some examples of where this pattern can fit into your games and how it can make your projects better.
    More Info: unity3d.college
    Join the Group: http:/unity3d.group
    Patreon: / unity3dcollege
  • บันเทิง

ความคิดเห็น • 154

  • @piotrw3366
    @piotrw3366 4 ปีที่แล้ว

    I really appreciate you doing those tutorial. I have searched and found countless of switch statement examples. This example with reflection usage is great. Thank you!

  • @jsarnowski
    @jsarnowski 5 ปีที่แล้ว +107

    You're the only one who teaches about real-world stuff, Jason! Everybody can do a Pong game having just a few classes - things can't get too complicated. But making any bigger game requires better code architecture if you don't want to get lost after adding a few mechanics. Thank you for that! I learn a lot from your videos and I know this knowledge is applicable to a real-world development process, not like Brackey's "How to create Flappy Bird" videos where the whole game logic is being put in one class :D I hope you'll keep creating :)

    • @thorham1346
      @thorham1346 5 ปีที่แล้ว +20

      'How to create Flappy Bird' is useful for beginners. Brackey's tutorials have their place.

    • @Alluvian567
      @Alluvian567 4 ปีที่แล้ว +7

      Yeah, SO many tutorials out there that are just setting people up to fail. I am very much a Unity noob right now, but even I get incredibly frustrated seeing beginner tutorials that don't even point out the pitfalls that they are leading people into. Example would be a tutorial that shows how to do hit detection for a simple shooter without even bothering to destroy the bullet objects. Even a small game is going to have problems there. Sure you don't want to have to explain object pooling in a total newbie video, but at least state the basic concept so they know they have another thing to learn when the time comes.

    • @WhoIsLym
      @WhoIsLym 4 ปีที่แล้ว +3

      @@Alluvian567 If a beginner tutorial described all the ways that they could make things better, the one following the tutorial will just be overwhelmed. You have to take it step by step.

    • @jayocaine2946
      @jayocaine2946 3 ปีที่แล้ว +1

      if you think that any programmer worth something would actually use pre-determined "patterns" like this you're out of your mind.

    • @JohnZyski
      @JohnZyski 3 ปีที่แล้ว

      Yes, this exactly.

  • @JulioCesarjcfalcone
    @JulioCesarjcfalcone 5 ปีที่แล้ว +74

    Good to see this kind of videos man, Sometimes is hard to visualize new patterns without good examples

    • @Unity3dCollege
      @Unity3dCollege  5 ปีที่แล้ว +4

      Glad it was helpful! :)

    • @Unity3dCollege
      @Unity3dCollege  5 ปีที่แล้ว +3

      Thanks!

    • @kippenegg
      @kippenegg 3 ปีที่แล้ว +3

      Yup, the examples do incredibly much when it comes to understanding the subject, which is one reason why i love his videos.

  • @noctisocculta4820
    @noctisocculta4820 5 ปีที่แล้ว +2

    Love how your examples always have something fun and semi real world use. Other programming tutorials always have some stupid accounting software or something weird.
    Studying software development, so these videos are amazing at helping me understand the course material.

  • @koishigarin
    @koishigarin 5 ปีที่แล้ว +1

    Thank you for such an interesting and important content, Jason! Can't wait to see next episodes.

  • @olinolmstead4490
    @olinolmstead4490 5 ปีที่แล้ว

    Great to see these patterns applied to games/Unity. Going to binge watch the others now...

  • @Besaids
    @Besaids 5 ปีที่แล้ว

    I would like to thank you for the awesome information you manage to relay in your videos, really helps roughing out some of the bad practices one might commit without prior knowledge to the use of some of these solutions, keep up the good work!

  • @eugenemigursky9608
    @eugenemigursky9608 3 ปีที่แล้ว +3

    Most underrated channel ever. Thanks for your tutorials.

  • @Denifia
    @Denifia 5 ปีที่แล้ว +8

    Thanks for another interesting video. I'd love to see more pattern videos like this!

  • @TheRicherthanyouguy
    @TheRicherthanyouguy 2 ปีที่แล้ว

    I’ve been looking for a good tutorial on the factory pattern and I really liked that this was using unity much appreciated

  • @criticalexpert
    @criticalexpert 4 ปีที่แล้ว

    Thanks a lot! There aren't many good unity design pattern tutorials out there. This really helped!

  • @KalechippsDev
    @KalechippsDev 3 ปีที่แล้ว

    Awesome video!! These kind of tutorials are hard to find--lots of great info here that's crucial for building an actual large-scale game, rather than making everything a Monobehavior. I'd love to see more!

  • @telephonedude
    @telephonedude 5 ปีที่แล้ว +25

    Hey Jason,
    Static constructors are definitely a thing! They get executed the first time a static property or method is accessed or called, so would behave the exact same way as your initialization method.
    I also feel like generics would be a better fit for factories like these (and keep the reflection for the UI script e.g.), but that's a whole 'nother discussion. ;)

  • @rodrigogarciasharpe5308
    @rodrigogarciasharpe5308 4 ปีที่แล้ว

    Thank you very much for all the knowledge you share with us, i've been trying to find these explanations and use cases for a long time, Game architecture can be so abstract and hard to understant for newbies, but you're a great teacher, very to the point and accesible. Gracias

  • @Ne0mega
    @Ne0mega 5 ปีที่แล้ว +1

    This has got to be my favorite video yet. This pattern is incredibly powerful. Jason said at the end "you cant shove this pattern into everything" but there is a part of me thinking, "watch me". :P This factory pattern is just really cool. The ease of extendibility is out of this world.

  • @jameslavery2958
    @jameslavery2958 5 ปีที่แล้ว

    Excellent! I really like seeing code that is implemented in this fashion. Thank you.

  • @CoReeYe
    @CoReeYe 5 ปีที่แล้ว +1

    Wow I loved the reflection examples!!

  • @ThoughtExperiment
    @ThoughtExperiment 5 ปีที่แล้ว +7

    Great as always Jason. Appreciate you.

  • @yayingzhang1506
    @yayingzhang1506 2 ปีที่แล้ว +1

    It's very helpful to see how you use the patterns in real unity examples!!

  • @goehlergamedev
    @goehlergamedev 2 ปีที่แล้ว

    I just love these architecture videos, mann!

  • @zeljkomitrinovic1146
    @zeljkomitrinovic1146 3 ปีที่แล้ว

    I can‘t tell why, but it is quiet satisfying to watch those patterns work.

  • @gregbriggs9225
    @gregbriggs9225 4 ปีที่แล้ว

    Great work!
    Going to check out your DI vid next.

  • @GrippingMoments
    @GrippingMoments ปีที่แล้ว

    Thank you! Very clear explanation!

  • @Tech_Alchemy
    @Tech_Alchemy 5 ปีที่แล้ว

    Great video Jason, very informative.

  • @nguyenphan8984
    @nguyenphan8984 4 ปีที่แล้ว

    another awesome video with great practical examples. Thank you.

  • @sikiroto
    @sikiroto 6 หลายเดือนก่อน

    the reflection part blew my mind!

  • @zekiozdemir420
    @zekiozdemir420 2 ปีที่แล้ว

    learned factory pattern and ability system at the same time thanks

  • @xlerb2286
    @xlerb2286 ปีที่แล้ว

    I do like your videos. You stay focused, and you keep the examples simple to show the core concepts and leave the complicating details to the comments. On that note...
    One thing I've found useful in creating factories is for any given type the factory can create to have the ability to specify that the type should always return a new instance or should return a cached singleton instance. Returning a singleton saves the overhead of creating a new instance. But of course that's not always the best approach, or may be the best approach only for some types the factory creates. Also as you touched on for a project of any size I would suggest using some sort of dependency injection that gives you the ability to swap out the types that will be created (whether that's a dependency injection library or just functionality implemented within your factory). Very handy for testing where you may want to mock some/all of the types the factory produces. Testing is just as important in games as it is in any other type of application 🙂

  • @joeyw8418
    @joeyw8418 5 ปีที่แล้ว +1

    I really like these kinds of videos!

  • @user-oc7ss1xb2x
    @user-oc7ss1xb2x 5 ปีที่แล้ว

    Thanks for wonderful sharing. Really like your videos about pattern. I've learned a lot.

  • @android272
    @android272 3 ปีที่แล้ว

    Great video! I want to learn more about patterns and these videos are very helpful.

  • @unDeadGod69
    @unDeadGod69 8 หลายเดือนก่อน

    Cool video. Learning to implement desing patterns in unity have been complicated for me jajaja

  • @mauritzandreae4278
    @mauritzandreae4278 2 ปีที่แล้ว

    Thank you very much for the great tips and explanations. It helped a lot! :)

  • @anthonygiannotti4228
    @anthonygiannotti4228 7 หลายเดือนก่อน

    Great explanation. Thanks!

  • @OTadashi162
    @OTadashi162 5 ปีที่แล้ว +6

    Oohhh yeah.
    This is why i'm here!!! ❤😁😁

  • @plopper7080
    @plopper7080 5 ปีที่แล้ว +2

    cheers man, this is a really useful tute

  • @dejo095
    @dejo095 3 ปีที่แล้ว

    Jason you're the best source for Unity devs, even better than their documentation lol

  • @xanaramus
    @xanaramus 5 ปีที่แล้ว

    Thanks for such quality and usefull content. Thank you!

  • @JohnZyski
    @JohnZyski 3 ปีที่แล้ว

    This has been very helpful.

  • @nandomax3
    @nandomax3 4 ปีที่แล้ว

    I'm watching your videos and I don't even work with game dev. But the concepts you teach are universal in the software engineering

  • @kpro9047
    @kpro9047 2 ปีที่แล้ว

    You are a rockstar, sir.

  • @DustVoltrage
    @DustVoltrage 4 ปีที่แล้ว +1

    Thanks for the great video !
    I do get how this patterns aims at making your life easier when expanding your project (you say so at the very beginning) but I'd like to know the pros and cons about building an ability system this way compared with Scriptable Objects or the new Prefabs (which are both pretty commun methods)
    thank you so much for all your hard work :)

  • @keriduprey5473
    @keriduprey5473 5 ปีที่แล้ว +2

    Hey Jason, Thanks for the Tutorials! I had stepped through with the debugger to try to better understand what's going on... in InitializeFactroy() "type" already contains the Name string. Changed the line to abilitiesByName.Add(type.Name, type). Works without instantiating.

  • @parthpandya008
    @parthpandya008 5 ปีที่แล้ว

    Hey Jason good use of Reflection too. Thanks!
    It will be great if you cover how c# reflection can be used in Game Architecture in detail

  • @ruslankudriachenko5673
    @ruslankudriachenko5673 5 ปีที่แล้ว +4

    Nice video but I don't like the idea of creating something to get the string with a name :)
    I would use attribute for that. Like:
    [AbbilityInfo(Name ="Health")]
    Not big of a deal, but looks cleaner. Thanks for video again.

  • @AyoubGharbi
    @AyoubGharbi 5 ปีที่แล้ว +1

    For the string ability type I would go for enums => more accurate and clear. Also here it could be better to use interfaces over abstract class.

  • @joerivde
    @joerivde 4 ปีที่แล้ว

    By far one the patterns I use the most

  • @LautaroArino
    @LautaroArino 4 ปีที่แล้ว +7

    Thanks! Great class. But why reflection and strings instead of a generic method taking Ability derived type. Or an interface?

  • @yerasisaiprasadreddy
    @yerasisaiprasadreddy 5 ปีที่แล้ว

    Thank you for making this video...

  • @finn9233
    @finn9233 4 ปีที่แล้ว

    imo it is way more effective to teach code like you do, explaining line for line and adding the background knowledge where necessary. Very nice teaching style, please more Pattern videos in context of game dev. Maybe some procedural generation

  • @rashidfarhan6223
    @rashidfarhan6223 5 ปีที่แล้ว

    This was interesting!

  • @ianfitchett2768
    @ianfitchett2768 5 ปีที่แล้ว +1

    Fantastic.

  • @judehariot8076
    @judehariot8076 5 ปีที่แล้ว +1

    What an awesome series of tutorials this was, really appreciated your work. I've been launched into a higher level of development skill. Thank you Jason. I've been going through your "SOLID in Unity & C#" series as well, and trying to figure out a way of converting the Finite State Machine into a pattern that honors the SOLID principles -mostly the Open/Closed Principle. But i've had no luck yet. Which has led me to ditching a FSM approach, and instead go for the state pattern explained in the Game Programming Patterns book you've recommended. Though unfortunately, i've ran into the same problem of failing to honor the SOLID principles when implementing the State Pattern. So what i really wanted to ask you, is if you could PLEASE cover the state pattern too. And how one goes about implementing it while honoring the SOLID principles. It would be an excellent addition to this playlist.
    Your biggest fan and student,
    Jude

    • @robbyscherpereel
      @robbyscherpereel 11 หลายเดือนก่อน

      th-cam.com/video/nqAHJmpWLBg/w-d-xo.html this will solve your open closed thingy btw, in case you still wondering 😋

  • @MasterofGalaxies4628
    @MasterofGalaxies4628 2 ปีที่แล้ว +1

    For anyone who's curious, you actually CAN have a constructor for a static class in C#. The syntax is pretty much the same as any other constructor, except it has to be marked static and ( as I currently understand it) cannot have an access modifier keyword, similar to an interface:
    public static class MyClass
    {
    static MyClass()
    {
    // code goes here
    }
    }

  • @piotrw3366
    @piotrw3366 5 ปีที่แล้ว

    Great video. I just would like to ask if in reflection ability example making the name a static string in Ability and hiding the base string in Children with "static new string" would be a valid way to solve the name problem - to avoid instantiating? What do you think? Thanks!

  • @toddschmersal798
    @toddschmersal798 5 ปีที่แล้ว

    If I were to make a moba or something similar in nature where different characters have a unique set of abilities, or even a game where abilities get unlocked throughout the game, would this be ideal?
    For instance, if I were remaking league of legends, I could in theory have one class for a skillshot, and on the individual character, house the projectile with distinct velocity, hitbox, etc.? Or would each unique character ability require it's own class?

  • @Haapavuo
    @Haapavuo 3 ปีที่แล้ว +1

    The next level would be to make a pool of objects that can be reused for cases where the created instances become obsolete over time. This will greatly reduce GC time and overall performance when dealing with hundreds or thousands of complex objects.

  • @thijsdevries9016
    @thijsdevries9016 5 ปีที่แล้ว

    good stuff!

  • @svetlinsvilenov8739
    @svetlinsvilenov8739 4 ปีที่แล้ว

    Greetings, really liked the video, and I'm now trying the pattern. One question I have now is how to go about having a sprite icon for the ability to put on the UI button

  • @FernandoMirabile
    @FernandoMirabile 2 ปีที่แล้ว

    @Jason, do you have a video or any suggestion to make a game with a lot of binding keys?
    Each key can trigger a different ability, like for example "Dragon Age: Origins" ?

  • @zandzpider
    @zandzpider 5 ปีที่แล้ว +2

    Have you considered using generics for these kinda things? would love to see your take on it =)

  • @huntercraft5674
    @huntercraft5674 ปีที่แล้ว

    Funny thing, i have watched this video roughly 12 times
    and given how half of those were during past year, its funny how i couldnt understand all the libraries he was using, so i didnt know where Type, Activator or Assembly were coming from...
    ;-; only now did i learn about it

  • @LordDecapo
    @LordDecapo 5 ปีที่แล้ว

    Subbed, do you plan on doing any videos on Unity Tiny?

  • @crabstar7312
    @crabstar7312 4 ปีที่แล้ว

    Thanks!

  • @RedLionYTB
    @RedLionYTB ปีที่แล้ว

    If you would implement IDispose to the abstract class, and then call it whenever you get an ability (also the dictionary would take a instance of each implementation of the abstract class), wont the program be more friendly to the GC?, or is this the only way factory pattern works?

  • @goose4878
    @goose4878 3 ปีที่แล้ว

    If you wanted a factory for, let's say, different types of enemies, would you make a separate factory for them, or put them into the same factory as this along with your abstract enemy class?

  • @user-vm3gp3qp9k
    @user-vm3gp3qp9k ปีที่แล้ว

    is there anytime in the video where u show the abilityButton script? i couldnt find it

  • @rafaelcorrea7959
    @rafaelcorrea7959 4 ปีที่แล้ว +1

    One quick note, I wouldn't get the abilities by the reflection, I woul rather use an array for that.
    Why?
    Because if I have abilities that I want to toggle (enabled or not), I would have to make a second check inside the ability and change through code. Using an array would open the possibility of a non coder tweaking those values (or even dynamically adding abilities through code).

  • @lln6123
    @lln6123 12 วันที่ผ่านมา

    thanks!

  • @acronym5231
    @acronym5231 4 ปีที่แล้ว

    I try to use factory pattern and there're too many if.. else to classify type. and i found this solution :D. Thank you!! but is this stable for mobile device? using reflection is good in runtime?

  • @alexchesser5209
    @alexchesser5209 5 ปีที่แล้ว

    Ooh... I learned something new with that "getter" pattern. ( Name => "name"; )

  • @SFotakos
    @SFotakos 2 ปีที่แล้ว

    Hey Jason, I know this is an older video but I'd like to ask what made the reflection factory more adherent to the open-closed principle?
    It's still looking for abilities by name, but now it's in a dictionary and all of them are mapped once you declare the class.
    You're pretty much cutting the switch case and the case creation from each new ability.
    Edit: In this scenario you didn't have to change the player because you're iterating the ability list to have each ability, but in most cases you'd have a customized call

  • @NilsMoller
    @NilsMoller 2 ปีที่แล้ว

    How would this work when an ability uses 2 pre-existing abilities? For example, a new ring of fire spell which uses both the fire ability and damage self ability. You can only have one base class, so how would that work?

  • @bernhardrubow5797
    @bernhardrubow5797 5 ปีที่แล้ว +18

    At 11:55 you say you can't have an constructor for an static class. That confuses me, because I use static constructors for static classes in my projects. These are automatically called, when the static class is used for the first time. Just followed your example and used the static constructor:
    static Factory() {
    ...
    }
    In there, I put your initialisation-code. Didn't know that for a long time, too. Saw it in a coursera video for the Unity Expert Gameplay Programmer Specialisation.

    • @dreamlabxr5121
      @dreamlabxr5121 4 ปีที่แล้ว +2

      They don't work the same way. Static constructors will get called only once as soon as the program runs, no matter how many instances are created. You also can't use parameters or access modifiers. I'd stay away

  • @cbr9731
    @cbr9731 2 ปีที่แล้ว

    Nice.

  • @anjumshakeel5832
    @anjumshakeel5832 5 ปีที่แล้ว

    Hey Jason. When are you going to make more of the Design Pattern tutorials in the series?

    • @Unity3dCollege
      @Unity3dCollege  5 ปีที่แล้ว

      Definitely! Is there one you wanna see next?

  • @LingoManiacs
    @LingoManiacs 5 ปีที่แล้ว

    Regarding performance like in mobile apps wouldn't it be better to avoid System.Reflection because it's kinda slow...? I'm currently using Reflection for creating several ScriptableObjects from a CustomEditor at once while feeding data from a CSV into these SOs, but not in runtime

    • @The28studio
      @The28studio 5 ปีที่แล้ว

      My suggestion is to filter you reflection , for example filter by name spaces , eg put your ability under a name space , the reflection will look only there so it's faster .

  • @whatshappeningharlow
    @whatshappeningharlow 3 ปีที่แล้ว

    Would be great if you could show your AbilityButton Script. Thanks!

  • @arsenbabaev1022
    @arsenbabaev1022 3 ปีที่แล้ว

    I would use scriptable objects to construct any objects or pass any data. creating many classes for everything/spell/weapon isn't too useful in game programming I feel like.

  • @richiebee33
    @richiebee33 9 หลายเดือนก่อน

    I don't like this kind of video. I *love* this kind of video. Thanks, Jason!

  • @danielospinacastrillon70
    @danielospinacastrillon70 3 ปีที่แล้ว

    Can anyone tell me what's in the "AbilityButton" Script?

  • @gdk870
    @gdk870 5 ปีที่แล้ว +1

    Hello Jason,
    I've been following this series, and am grateful for the work you've put in.
    I've also been reading the book and following along with your videos. All these patterns have been super helpful, but there is one other pattern discussed in the book -called the State Pattern. I'm almost done understanding it, but wanted to know if it's a worthwhile pattern to know in Unity -since you haven't covered it in the series. Might your reasons be that the state pattern is insufficient, and that those you've covered are all we'll need thus far?
    I'm eager to hear from you.
    Cheers

    • @Unity3dCollege
      @Unity3dCollege  5 ปีที่แล้ว

      Yes, I'll definitely cover that soon. It's a very important one IMO and I've talked about it in a few places but not in this series where it belongs yet :)

    • @gdk870
      @gdk870 5 ปีที่แล้ว

      @@Unity3dCollege Okay good to hear. I'll be looking out for your video then.
      Cheers

    • @judehariot8076
      @judehariot8076 5 ปีที่แล้ว

      I'm with you on that request. It's hard to manage state and still honor the SOLID principles. I really hope Jason reads this (hi Jason), and can give us a video on the topic soon. This is maybe the best unity architecture channel on TH-cam.

    • @gdk870
      @gdk870 5 ปีที่แล้ว

      @@judehariot8076 Yep, i'm 100% with you on that one. Though you'll be glad to know that he already has a State Pattern video in the works. Got confirmation from him via email, so fingers crossed, hoping we'd see it next week.
      Cheers

  • @marcinmd4186
    @marcinmd4186 ปีที่แล้ว

    Why not create a static constructor to contain what InitialiseFactory does at 12:50?

  • @endihidir2087
    @endihidir2087 4 ปีที่แล้ว

    ScriptableObjects are also about Abilities in Games. So when we should prefer Factory pattern instead of Scriptableobjects?

  • @WillowThomkin
    @WillowThomkin 2 ปีที่แล้ว

    A suggestion, this, but this time with mono scripts to install custom classes onto a scriptable object.

  • @janw6923
    @janw6923 5 ปีที่แล้ว +2

    how does the abilitybutton script work? So how do I actually call an ability? I would be glad if someone can help me

    • @aurelienlerochbermuda6600
      @aurelienlerochbermuda6600 5 ปีที่แล้ว +5

      private void OnClick() { AbilityFactory.GetAbility("the name").Process();}

  • @dopplegangerdavid
    @dopplegangerdavid 2 ปีที่แล้ว

    I like the explanation, but it would have been nice if there was an example I could relate to.

  • @MTrax
    @MTrax 4 ปีที่แล้ว

    Quick question about reflection and performance. I come from an Android mobile app background and always feel that reflection is pretty slow. Can this become a problem in C# on usual consumer machines? Or might this be a problem when the target platform is mobile? Is C# reflection very slow? Saw you using reflection many times now. You know what you are doing, but I am just asking to be certain.

    • @MTrax
      @MTrax 4 ปีที่แล้ว

      Nevermind. I just realized that you use reflection only for instantiation and not on Update.

  • @r1pfake521
    @r1pfake521 4 ปีที่แล้ว

    You can have a static constructor in C#, otherwise good video.

  • @ianfitchett2768
    @ianfitchett2768 5 ปีที่แล้ว +8

    I have been trying to implement this myself and am having a hard time, I have probably watched the video 10+ times and have not seen where you show the AbilityButton Script. Without it the ButtonPanel script will not compile because it AbilityButton isn't defined. I tried stubbing it out with a basic class named AbilityButton and a method SetAbilityName but when I try to run this the line that instantiates the AbilityButton prefab fails with a null reference. This makes sense to me since all you did was declare buttonPrefab, it's value is never set in your code, so I don't understand how in your project the buttonPrefab is actually getting initialized. I also don't see a link anywhere in the description to a sample project.

  • @darryljf7215
    @darryljf7215 3 ปีที่แล้ว

    It's not possible to use this pattern, if your abstract class inherits from MonoBehaviour -- is it ?

  • @arthurgentz2
    @arthurgentz2 5 ปีที่แล้ว

    Greetings Jason,
    I'm lucky to have found your work. Are you planning more videos covering the patterns mentioned in Robert Nystrom's "Game Programming" book? If so, then i'm definitely looking forward to them. I'd also like to suggest a video on how to manage state. The book discusses the topic, but makes use of switch statements. Which after having gone through your SOLID principles series, seems a little bad in practice. Especially if the number of states grow beyond 5. I can imagine states increasing over time, and the switch statement having to grow in its case clauses -ugly business. Any way, i'd be interested to see how you'd implement something a long the lines of the problem i just briefly discussed.
    Thank you, and please take care.

    • @Unity3dCollege
      @Unity3dCollege  5 ปีที่แล้ว

      The State pattern is the next one I'm doing from there :) Should be out sometime this month

    • @arthurgentz2
      @arthurgentz2 5 ปีที่แล้ว

      @@Unity3dCollege
      That's great.
      I'm genuinely looking forward to it.
      Keep it up. Cheers.

  • @Ne0mega
    @Ne0mega 5 ปีที่แล้ว +1

    If you completely suck at UI, like me, and it never makes sense, you got lost at about 9:20.... ...To continue, add the panel in the heirarchy (create - > UI -> panel), then you add the button,

  • @corbucci69
    @corbucci69 4 ปีที่แล้ว

    what if we just want the object to appear on the screen? (rather than an ability)

  • @TheDiggidee
    @TheDiggidee 4 ปีที่แล้ว

    Personally I would have used Generics instead of reflection.
    public class AbilityFactory
    {
    public T GetInstance() where T: Ability, new()
    {
    return new T();
    }
    }

    • @Unity3dCollege
      @Unity3dCollege  4 ปีที่แล้ว +4

      In that case you'd be instantiating and generating extra garbage for the gc. The goal of the reflection part was just to keep single instances of them and use them from data, without having to add code in multiple spots for every new type. Also came from a scenario with over 100 types now where they're constantly getting added.
      That said, I do love generics tho :)

  • @Faygris
    @Faygris 4 ปีที่แล้ว

    I love to learn about things like this. But I have to say, I still don't really understand why I would need such a factory to return me objects, when I can just instantiate them directly.

  • @Kenbomp
    @Kenbomp ปีที่แล้ว

    Bit complicated bit it works .

  • @rlm657
    @rlm657 5 ปีที่แล้ว

    i like

  • @stormcoast910
    @stormcoast910 3 ปีที่แล้ว

    Couldn't you just use a static constructor for the static Factory instead of the InitializeFactory Method? Then you wouldn't need to check whether it was already initialized and wouldn't have to call that initialize because that happens automatically before the dictionary is first used.

  • @madhusudansharmah2007
    @madhusudansharmah2007 ปีที่แล้ว

    What is Type in the dictionary?