Download

[Clarification] Best way to handle changing pawn classes

For my game the player will be a TP or FP player in control of a boat. The boat will change over time (meshes, upgrades etc.) as the player gets new ship designs and technologies.

What would be the best way to handle this, in a team setting, so that everything can be changed as need be, but other classes like widgets and the gamemode/PC etc. can access it without breaking if something changes.

Right now I’m using class inheritance Pawn > Vehicle > Boat > Individual boat classes that can be controlled but the only way I can think to make that used is to have a struct in the GameInstance that sets the current players pawn class and have all classes cast to GI and get that class then cast/spawn/find actors of that class.

Would I be better off just having one class for all the boats an just switch out meshes etc. for all the technologies and classes. Were talking about 50 years of naval technology here…

Your description of what your having trouble with is a little confusing.

I think you need to do some research on Interfaces, they allow you to “anonymously” make function calls on Objects and have those Objects respond based on their own needs/implementation.

I think thats what your after?

I’m pretty sure you are trying to decide between using Polymorphism and class hierarchy versus using a component system.

It’s really up to what you are most comfortable with. Because you have so many different bits a component system will probably be easier to manage, but who knows. Also as DevilsD said using an Interface, or Interfaces can also help you.

Thats the idea, my programming skills just arnt strong enough to fully comprehend anything more than parent/child classes versus a component setup.

DMy main issue is when I made a new class of ship which had totally different parts and I had to go around changing my widgets etc. to choose between multiple classes properly. Interfaces have always confused me I cant think of one instance where ive used them.

Have to read up on then in P&P in C++

Thanks for the input

Its not so much polymorphanism (had to review OOP for that) all the ships will share most of the functions its just keeping track of crew, speed, heading etc. without it breaking when you upgrade your boat class (which would be a child class currently) or add on technologies (which could be adding extra functions in a tertiary class or maybe components who knows)

Does sound a bit confusing.

Do what is simplest for you to understand, even if that means there are more classes then go that route.

The problem is if I have 25 classes for player controllable ships over the entire game and the couple dozen widgets have to pull info from them at any time I need to figure out the best way to be able to change classes in one place and be able to not break anything everywhere else, I was thinking a struct or even just a class set in the game instance.

You do not have to cast to the subclass, that’s the whole point of Polymorphism. Have the needed functions in the base class, if a subclass needs to it can override them.

Or, as DevilsD suggested, use an Interface. That will also eliminate casting.

Or, do a combination of both.