Problem casting with character parent


I hope I can explain this well. I currently have a system with a character customizer this system works by having a parent Character class that has a character customizer component and it has two children one for a Male character and one for Female. I have a Boolean that determines if it’s supposed to be a male or female character and spawns the character based off of that. So I have a lot of forking logic. So in order to get a general reference to things I do a cast to the parent class but this cast sometimes fail, especially since I’ve been dabbling with multiplayer. I’ve tried to get around this by spawning the parent class but that doesn’t seem to work.

I guess my question is this, Is there a better way to do this where it’s just one overall class? That maybe somehow I update the mesh based off male or female, so that I don’t have to cast to two separate classes?

If you need more clarification, please let me know

Thank you.

if you have a reference to the child that you are casting to the parent then it should never fail. but if you wanted to use a different system you could without too much issue. if you are selecting a gender then spawning the character then you could easily use a set skeletal mesh in the construction script, and have a variable for the gender. then make the variable exposed on spawn so that you can set it prior to the character being created. then you just need a way to set the variable. there may also be other settings you need to set as well, for instance the anim bp if its a different skeleton.

you could also just save the variable value in the game mode / game instance then when the character is constructed get the value from the game mode.

So I could have one anim_bp if there are two different skeletons?

I don’t have a problem casting to the children, I have a problem casting to the parent so that I can control the children in lets say the player controller.

Sorry for the late reply. I’m currently trying to wrap my head around refactoring the blueprints to make this possible.

no only one skeleton can be used per anim bp but many skeletal meshes can share the same skeleton. i realize you are trying to cast to the parent class but you still need a reference to a actor for the object pin. your were saying that the player character was one of the children, so you would plug a reference to the current character (the child) into a cast to (insert parent class here).

if you were attempting to do this from the player controller then you would need something like get player character → cast to parent class → do the script you want.