Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity Principles Video

Discussion in 'General Discussion' started by Kiwasi, May 10, 2015.

  1. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    HI all.

    A new video series I'm messing around with. I'm interested in what people think of the format, and if there would be a demand for more videos like this. Suggestions for future episodes would also be welcome.

    The intent is to talk about the why behind coding and design inside Unity. Most of the tutorials I've seen so far focus on showing you how to code something. I'm trying to fill the gap on why you code something.

    This video in particular talks about inheritance and component based design.



    This one about script to script communication

     
    Last edited: Jun 3, 2015
  2. wbailey79

    wbailey79

    Joined:
    Apr 30, 2015
    Posts:
    39
    Hi. I just wanted to give some quick feedback on your video as a person new to Unity, and as someone who has Zero coding experience.
    I liked the video, and I think it was fairly easy to follow.

    From my understanding (And please correct me where I am wrong) Component based design is associating individual components to achieve a game object or entity. Similar to a child's building blocks being used to construct individual buildings, or in the case of characters Lego people, action figures, dolls or whatnot.

    2 of my sons Lego people cannot share the same hat at the same time, instead if both figures are wearing the same copy of a blue hat, each figure being similar. However if I switch one of the Lego persons blue hat, with a pirate hat, then I am changing one of the components associated with that figure.

    The problem with Traditional Inheritance as I understand your video, is when a major change is done to a component then the entities can no longer share that component.

    If the Lego people above really could share the same blue hat (of course they can't), then adding a pirate hat to one of them would present an inconsistency.
     
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    Problems can arise because you can only inherit from one class at a time, so if you have a "WearHat()" function inside Human.cs, and also want Dogs to wear hats, you can't make the Dog inherit from Human because it's already inheriting from Animal. You might be stuck with having to copy & paste the WearHat() function into Dog.cs.

    Instead, you can just have a Hat component that can attach to both the Human and Dog.

    Inheritance is useful for sharing data with children/subclasses. If you had a Hat component that you put on a Human and a Dog, then they'd both be wearing hats in the same way (running the same WearHat() function). For it to be unique you can use Interfaces, or inherit from Hat and override the default WearHat() function.

    Inheritance is fine as long as it doesn't get too deep. One level of inheritance can be useful.
     
    wbailey79 and Kiwasi like this.
  4. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Avoiding discussion about more general things like how to use inheritance, composition, and focusing on the video itself...

    I think you need to also provide more specific details. I just don't think that someone viewing the video would be able to put those ideas into practice, given the very abstract presentation.

    Maybe you could break future videos into like 3 minutes on the abstract and 3 minutes of actual example (showing code, editor, etc).
     
    wbailey79 likes this.
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This is certainly true. I use inheritance this way quite frequently.

    Thanks for the feedback. The choice to be code free was a deliberate one. There are a lot of existing tutorials to teach you how to write code. But not so many that focus on the abstract principles. That's my observation anyway, I'll see how well the series is receive in general to know for sure.
     
    wbailey79 likes this.
  6. wbailey79

    wbailey79

    Joined:
    Apr 30, 2015
    Posts:
    39
    @Stardog thanks for taking the time to explain this better. I am sure it is something that I will develop a better understanding of once I progress further in my learning.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yeah, sometimes the best teacher for best practices is doing it wrong and getting bitten. Experiance certainly helps.
     
    wbailey79 likes this.
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    How do I access a variable on another script gets asked a lot around here and answers.

     
  9. swyrazik

    swyrazik

    Joined:
    Apr 21, 2013
    Posts:
    50
    According to your presentation about this series:
    I'd say this video is more about the "how" than the "why". And if you explain the "how", it's better to have at least one example of actual code in my opinion.
     
    Kiwasi likes this.
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Fair enough. A couple of viewers have said this video would have been better with actual code examples. I'll take that on board.

    I'm trying to keep most of the discussion at a higher level then actual code, there are plenty of other series that teach how to code, including Unity's own learn section. We'll see how it goes, but my design intent was to show as little actual code as possible in the series.
     
  11. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    I like it. I don't think you should add code, I like the idea of sticking to explaining concepts.

    Side note, now I have to read all your posts with an accent.
     
    Ryiah and Kiwasi like this.
  12. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    You can't please all the people all the time! I thought this was a very solid video.

    In terms of a happy medium between higher level ideas and code, a relatively easy way might be something like "use GetComponent" then you could add a video annotation with a link to the manual page or some other reference. This might be a happy compromise.

    Another alternative that may require considerably more work would be taking quick screenshots of a code page maybe with a 'Bullet' game object field circled. And a screenshot of the editor with the bullet field populated. This would help ground people who have some basic knowledge in the ideas youre talking about.

    It's sort of hard for me to imagine what I would get out of this as a really beginner coder. But I think the big revelation is that you would have a separate script for:
    • Gun
    • Bullet
    • Life
    • Death
    • Score
    You may not actually go into this in depth, but just mentioning them all as separate might really be a revelation to some people.
     
    Kiwasi likes this.