IsInputKeyDown Causes Crash if Called Outside of PlayerTick in Multiplayer at Client Game Start

Dear Friends at Epic,

I’ve run into a crash several times now related to PlayerInput component in Multiplayer games.

It seems that there is a brief moment during game start where the client player controller exists, but the player input component of that player controller does not yet exist.

Within playertick, this not an issue because playertick somehow accounts for whether playerinput component is null or not.

but

I’ve tried to call on playerinput outside of player tick through looping timer functions, that are running at game start, and this causes crash cause playerinput is not valid yet

that’s fine, that’s my programming fault, and it’s easy to check whether playerinput is valid

however


I just ran into a crash using IsInputKeyDown, called outside of playertick, during first few moments of multiplayer game when client is joining

I can only assume that IsInputKeyDown assumes that the playerinput component is valid when it is called.

Can you check whether IsInputKeyDown checks whether PlayerInput is valid before doing the rest of its code?

I’m only trying to help out with my suggestion here, and I cannot check myself for lack of .cpp access


Again, this is only an issue during first few moments of a multiplayer game before the client has fully joined the game and their playerinput has become valid

it does not happen in single player games with the same code.


the code below is running in a tick function on an actor that is spawned at same time as the player controller, and its tick function apparently starts up before the PC’s player input component has become valid

//VictoryPC = the PC, acquired as soon as it is spawned, 
//before playerinput component fully set up in multiplayer, apparently
void AVictoryPower::ProcessKeyInput()
{
	//Causes crash in multiplayer frequently
	//	if dont verify playerinput is valid
	if (!VictoryPC->PlayerInput) return;
	//-------------------------------------------------------
	
	if(VictoryPC->IsInputKeyDown(EKeys::X))  <---- crash here

Again my only point here is that the function IsInputKeyDown should not cause a crash, it should check whether the PlayerInput component is valid (if it is not doing so already). If it is checking, well then I dont know why it caused a crash, but the PlayerInput null check does solve the issue either way.

Just trying to help make UE4 even more awesome!

Rama

I went ahead and did a pass through the various player controller get functions and protected against cases where PlayerInput is NULL.

Thanks for the report.

You’re welcome Marc!

:slight_smile:

Rama