Forum begins after the advertisement:

[Part 8] not an issue, but general question

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 8] not an issue, but general question

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #13170
    Silver Supporter (Patron)

    You might have covered this at some point, but if so then I missed it. Throughout the series with onTriggerEnter2D and the like, you typically add an underscore in front of “collision” or “other”:

    private void OnTriggerEnter2D(Collider2D _collision)

    What is the benefit of doing this instead of leaving it as is?


    Hi Courtmaster, there is no particular performance benefit, but some programmers prefer to name their variables differently depending on whether the variable is public or private, and the _ is one way to differentiate between different kinds of variables. For example, the _ is commonly used as a prefix for private variable:

    public class MyScript {
        public int myPublicVariable;
        private int _myPrivateVariable;

    In this case here, Matias or Kiefer probably decided to prefix _ to their function parameters to make it easier for them to distinguish between these and their class variables.

    Silver Supporter (Patron)

    Ah, gotcha. Thanks for the clarification. You’re a legend!


    No problem Courtmaster. Thank you for your support!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Go to Login Page →

Advertisement below: