I think it's best here to clarify how you are using the new
keyword. new
can be used in two fashions. As an operator and as a modifier.
new
"Operator"
The new operator is used to create objects and invoke constructors, for example:
Class1 MyClass = new Class1();
new
Modifier
Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier.
Consider the following class:
public class MyBaseC
{
public int x;
public void Invoke() {}
}
Declaring a member with the name Invoke in a derived class will hide the method Invoke in the base class, that is:
public class MyDerivedC : MyBaseC
{
new public void Invoke() {}
}
However, the field x will not be affected because it is not hidden by a similar name.
Name hiding through inheritance takes one of the following forms:
A constant, field, property, or type introduced in a class or struct hides all base class members with the same name.
A method introduced in a class or struct hides properties, fields, and types, with the same name, in the base class. It also hides all base class methods with the same signature.
An indexer introduced in a class or struct hides all base class indexers with the same signature.
Since you are name hiding and declaring a Maptile
type but initializing to a child GrassTile
type AND parent MapTile
type never initialized your Texture
member is the reason why you seeing a null
.