Download

RPC function broke multiplayer support for my game

Hello friends,

I coded a simple RPC function to make my character sprint. It works perfectly fine for SinglePlayer but for some reason when I try to play it in multiplayer with 2 players in PIE UE4 crashes. I figured out it must be somehow related to the networking code I wrote. But there are no errors, no logs nothing. Just crash. No minidumps, nothing.

Here’s the code to my RPC functions:



void ABaseHero::SetSprinting(bool bNewValue, float fNewValue)
{
	bIsSprinting = bNewValue;
	GetCharacterMovement()->MaxWalkSpeed = fNewValue;

	if (Role < ROLE_Authority)
	{
		ServerSetSprinting(bNewValue, fNewValue);
	}
}

bool ABaseHero::ServerSetSprinting_Validate(bool bNewValue, float fNewValue)
{
	return true;
}

void ABaseHero::ServerSetSprinting_Implementation(bool bNewValue, float fNewValue)
{
	SetSprinting(bNewValue, fNewValue);
}


Everything seems fine for me here. If you guys need it I’d post my entire class code.

EDIT: Okay so I tried some debugging and realised that even if I start in singleplayer in stand alone game, pressing shift key (as it’s mapped to my sprinting functionality) causes crash.

Nothing wrong with the code you posted, as far as I can tell.

Make sure you run from ‘DebugGame Editor’ in Visual Studio, and uncheck the ‘Use Single Process’ checkbox in the advanced PIE drop-down menu. Also set the editor to ‘Play As Client’, which will allow you to debug the client in Visual Studio and not the Server.

Thank you, actually the problem was that I was hot reloading the game and closed the editor, compiled in Visual Studio and then ran UE4 again and it worked. Seems like the Hot Reload feature is not very reliable tool. Only to find out that, I lost 3 hours :frowning:

Yeah it depends what you’re doing, but a lot of the time it’s good to just hit the ‘reload’ button in VS and start fresh. I never hot-reload in editor when I change a header file.

Only adds a few seconds anyway while you wait for the editor to boot up, which is usually quite fast.

Weirdly, it takes around 15 seconds for me which is a lot when I’m doing small changes to the code and test if it works.