- Home /
I need to make two bullet controllers (friendly and enemy) Should I inherit?
Hey, so I've made a bullet controller, which, for the most part, works fine. But then when I inherit from it and make an EnemyBulletController, I get the good ol' "The same field name is serialized multiple times in the class or its parent class."
I'd do this to save time and retain all of the fields easily, but it seems there's a lot of hassle to get the inheritance working properly, so my question is this:
Would you recommend that I'd just make two separate classes which are practically the same? I think I originally didn't do it this way because it almost seemed like a coding capital sin, surely there must have been a way to make it more flexible and direct!
But nah, it seems there isn't so far, and it's preventing me from properly compiling my build. So, what do you say? Should I just duplicate them and update them manually as I make changes on them or is there another way?
Cheers!
Answer by Larry-Dietz · Dec 23, 2017 at 10:57 PM
Personally I would use inheritance for this. The game I am currently working on has 3 levels of inheritance going on, and is working just fine.
The variables in the base class do not need to be added to the inherited classes, that is what causes the error you are referring to. You can just use the variables from the base class directly in the inherited classes.
If you cant get rid of those errors, post your base bullet class and one of your inherited classes, and I am sure we can figure out how to get rid of those errors for you.
-Larry
Yes, this worked. Apparently I wasn't quite understanding how inheritance really worked. Everything gets serialized automatically on the inherited class, so there's no need to re-define anything.
Thank you!