I’m working on a game where you can switch between 3 characters at any point during runtime. The 3 characters are children of a master character BP and share the same functionality. This master character BP is based on the ThirdPersonBP from the normal template.
I have a CharacterSelect blueprint with the following functionality:
When Movement Mode for one character changes, the Movement Mode for the other 2 changes as well as soon as I possess them! If I jump and switch in mid air, the character STAYS in mid air. If I set the Movement Mode of one character to Swimming…the Movement Mode of any possessed pawn will also change to Swimming.
Is as if the Character Movement that I reference is changing at the parent level and not the child level (even if I specifically reference the child)
Please take a look at this 1min video to see what I’m talking about: [Youtube Video][5]
Can anyone tell me what Im doing wrong here? I want to have one character swim, while the others walk / jump independently.
In the definition of ACharacter (the parent class of ThirdPersonCharacter) in Engine/Source/Runtime/Engine/Private/Character.cpp about line 1003 (in branch 4.15 at the moment) it has:
//
// Static variables for networking.
//
static uint8 SavedMovementMode;
So, your result is not surprising. The ACharacter parent class stores the movement mode in a static class variable that would affect any and all instances of the class or any subclasses.
I don’t know much about the networking side of C++ (yet), so I couldn’t say if they really need that variable to be a static class variable in order for it to replicate across the network, but that’s what’s causing the behavior you see.
Thank you for your answer CleanCut! I haven’t looked at C++ in UE4, just learning Blueprint. From your answer it sounds like what I want to do is not possible if I’m using the Character class. I’m very surprised that this is the case, but perhaps there is a reason because of multiplayer.
Do you have any suggestions besides changing source code or using the Pawn class to achieve this?
Well, if you are looking for something to be done in blueprints then the only thing I can think of is making your own Pawn subclass blueprint and implementing all of the character functionality by yourself (probably a pretty massive undertaking).
If you are willing to build your engine from source you could experiment with some simple tweaks and see if it works for you. For example, if you aren’t using networking maybe it will “just work” if you remove the static keyword from that line I mentioned so that the movement mode is stored per instance instead of globally in the class.
Thanks for the clarification CleanCut. I think both options are probably too much for me at the moment. I ended up restricting when you can switch characters to prevent those issues.