- Home /
When calling the parent's method...
When calling the parent's method from one of its children via base.MethodNameHere(), should I pass a reference of the child using the "this" keyword as an argument (base.MethodNameHere(this))? Do I need to pass the reference if the method doesn't accept arguments in the first place? I noticed that no errors are thrown if I do include the "this" keyword as an argument, even for methods from the parent class which don't require arguments.
Answer by Vega4Life · Dec 16, 2018 at 01:48 AM
No, you don't pass 'this' by calling the base.Method(). I am skeptical you aren't getting errors if you pass a argument to a base method that doesn't take a parameter... because it absolutely should. You are basically saying there is an overloaded function with the same name.
you're absolutely correct. also, the reason I wasn't getting errors was because I was working in the script file outside of the unity editor. I opened the file directly from my cpu ins$$anonymous$$d of opening it through my unity project. I guess you have to open the file through the editor to ensure compilation, and when I tried passing "this" the error was there.
thanks for chi$$anonymous$$g in though!
Your answer
Follow this Question
Related Questions
An OS design issue: File types associated with their appropriate programs 1 Answer
How to work with a list of base class, if a variable is only found in some subclasses? 2 Answers
Game architecture best practices 3 Answers
OnDrawGizmos for parent and child class 1 Answer
Derived Class Fields 3 Answers