Getting the same variable from two different classes?

So let’s say I have two classes, Pig and Wall. Pig inherits from Mob, which inherits from PhysicalObject, while Wall directly inherits from PhysicalObject. Now let’s say I need to access a common variable from anything that inherits from PhysicalObject, which could be Mass. But I can’t just SomeObject.GetComponent().Mass, as that would only work for the Pig class, and I can’t say SomeObject.GetComponent().Mass, as I don’t think I’ll ever even attach that class to a gameObject because it is purely for inheritance purposes. Could I somehow do a check to see if whatever class I’m dealing with inherits from PhysicalObject somewhere down the line?

If PhysicalObject owns Mass, you certainly can:

a = SomeObject.Mass;

On Pig and Wall. Since you said that a common variable from PhysicalObject could be Mass, and through Mob Pig gets it just as Wall does.

Since Mass is a member of PhysicalObject, I see no reason for GetComponent, as it’s a member of PhysicalObject, not a component on a gameObject, if I follow your description as stated.

I think you don’t really understand what inheritance means. If Pig and Wall are derived from PhysicalObject they are PhysicalObjects, just more concrete types. You can simply do

float mass = SomeObject.GetComponent<PhysicalObject>().Mass;

This will work even when the actual class is a Pig or Wall instance or anything else derived from PhysicalObject. That’s the main purpose of OOP to treat a concrete class in a more general / generic manner.