Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to translate previous skills?

Discussion in 'Scripting' started by LordOfTheGulags, Jan 26, 2019.

  1. LordOfTheGulags

    LordOfTheGulags

    Joined:
    Dec 29, 2016
    Posts:
    2
    Hi everyone!

    Sorry if this is the wrong place to post this, but I wanted to get into small-scale game development for a while now, but I'm struggling with getting the hang of scripting.

    Some backstory is that I'm a junior in software engineering and I have quite a lot of experience (for my age) with development in Java, Python, and some Arduino/C/Assembly, so I wouldn't consider myself clueless, but each time I try to write a script or especially watch a tutorial video - I feel like I'm trying to understand a foreign language that I've never seen before due to the use of Unity-oriented packages, functions, etc...

    Does anyone have any tips on translating general programming skills to Unity specifics?

    Thank you all in advance!
     
  2. TheFunnySide

    TheFunnySide

    Joined:
    Nov 17, 2018
    Posts:
    200
    Tip 1) In Unity a variable can be set in the editor outside of the script.
    So anytime there is something used that is public but never initialized than expect ecpect it was set in editor.
    Tip2) In Unity objects are connected with transform trees. You can move the trees via parent /getChild
    You should learn about this in some video.
    Tip3) The Editor loves to initialize variables to length 0. this can break some of your code
    Tip4)At some point you want to learn how to customize your editor.
     
    Kurt-Dekker and LordOfTheGulags like this.
  3. LMan

    LMan

    Joined:
    Jun 1, 2013
    Posts:
    493
    So Unity has a lot more going on with it than just code- You feel lost because it's a forest. You're gonna have to spend a little time with the interface just so you know where things are.

    You get around in the 3D world with
    • Vectors (x,y,z)- this can describe a point in 3D space, OR a direction- and also if you use the magnitude, it can describe velocity.
    • Quaternions (x, y, z, w)- this describes a rotation in a way that doesn't suffer from gimbal lock like euler angles do. luckily, you don't need to know how to compute one- just use LookRotation to make one that points where you want it to.
    • Interpolate over Time from one point to another or from one rotation to another using:

    You make prefabs by setting up Gameobjects with the functionality you need, then dragging them into the Asset window. Voila, now you have reusable content you can put anywhere. Make an enemy, make him a prefab. Instantiate that sucker wherever.

    Code (CSharp):
    1. public float foo = 1f; //This will be exposed in the editor
    2.  
    3. [SerializeField]
    4. private bool hasHealthPotion = true; //This will also be exposed, even though it's private.
    You put any assets you need to load at runtime into a folder in your project directory called "Resources." (Stuff like JSON files. Or stuff you don't want to point to directly with a variable, but instead grab later.)

    Animate stuff by hand if you want it to interpolate in a particular way that isn't easy to describe with easing functions.

    Design Patterns hold up in Unity. Need a Manager to keep track of things over multiple scene transitions? That's probably a singleton. Need to build things procedurally? Most likely gonna use a factory. Have n classes that need to know if some value changes? Observer. Have objects you use and re-use often? Object Pooling is your friend.

    Don't neglect Unit tests. You don't have to go crazy with it because you're gonna refactor a LOT, but you're going to want a way to test a feature so that you can iterate quickly and not waste a bunch of time trying to verify if your change works and doesn't break previous functionality.
     
    LordOfTheGulags likes this.
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    Not mentioned yet, and probably the most confusing thing for me starting off: Unity has many "magic" methods that gets called automatically at specific times. Examples are: Start, Update, FixedUpdate, OnCollisionEnter, etc. The following should help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html

    Basically, if a MonoBehaviour class contains certain specific methods, those methods will be automatically called at the appropriate times. For example:
    • Start() is called once when the object is instantiated, usually when the scene starts unless you load an object dynamically later.
    • Update() is called once every frame. Place code here that changes the position or appearance of an object.
    • FixedUpdate() is called once every .02 seconds by default, and is used for Physics interactions.
    • OnCollisionEnter() is called the objects' collider hits another collider.
    These methods are confusing at first because A) They're used a lot, and B) You won't see anything explicitly calling them. (Anything that feels like "magic" in a framework can be confusing.)
     
    LMan likes this.
  5. One more advice (which usually isn't popular among developers with Java-background): in the main game loop, where you handle the heavy lifting (rendering happens, game logic, state changes, etc), sometimes you will need to give up some (or sometimes all) of the enterprise software development habits. When you start to develop action-packed games, maybe on low-powered devices, you will optimize for performance first.
    You probably won't do it at first, or second, but it's good to know that game development is a little bit different from the enterprise world. First rule: no one care about the pristine, readable, testable, etc code if your game does not work or freeze in every 5 seconds. Rule number two: working game, then you may care about the looks and the readability. Also, don't be scared, you will find a good balance, it matter of practice. (And of course it also highly depend on what kind of projects you will do)
     
    LordOfTheGulags likes this.
  6. LordOfTheGulags

    LordOfTheGulags

    Joined:
    Dec 29, 2016
    Posts:
    2
    Thank you for your responses, I feel much more confident to dive back into it now after reading up on the suggested topics! I was honestly blown away by the friendliness of the community and the desire to help.
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    That's actually a really nice and tidy little random slice of "oh this will make me think about what I'm seeing here in Unity for the first time." There's so much more, but that's a great digestible start. Bravo!