Inputs for multiple characters


I am creating an RTS game and each unit spawned during runtime is a character deriving from a Character BP. And here appeared a problem that I have not managed to resolve yet. How to disable/enable inputs for certain characters at runtime? The disable/enable input node does nothing in the event graph as a character class doesn’t even have a property of input disabling/enabling.

Set a bool(inputEnabled for example) in the character’s blueprint to false, use a branch and check for inputEnabled. If inputEnabled == true, then do whatever you normally want the character to do.

I thought about that, however, the problem is that the characters simply do not receive any input, so creating a variable will change nothing, because the events like LeftMouseClick will not even execute. The only character in the scene that is capable of receiving input is the one specified in the GameMode in DefaultPawn Class (created upon the game start).
I was also thinking of a rather quirky solution to that (maybe anybody here could suggest something more convenient? :slight_smile: ). I could create an invisible Actor BP, which instance would be placed somewhere in the scene and it would handle all the input input and distribute it to corresponding Characters. This should work, but might become problematic when the game becomes more complicated and multiplayer gets implemented.

If the characters are spawned from the player itself then references to the characters can be stored on the player at time of spawning into an array of owned character. Also references to objects can be set from the game mode blueprint, which would have access to world objects. You can also get a reference to the characters through a raycasting, which would be triggered from your player controller’s mouse click event. Using the default character is essentially the same thing as creating an invisible Actor instance, it would just be extra work to use something that will use the same functions that the player controller is already setup for.

The characters might eventually be destroyed during gameplay, so if the default pawn character is destroyed then the array is too.
I will try handling the input with GameMode BP most probably then :slight_smile: