Need help with adding Multiplayer Functionality to First Person Template

Hello,

I’ coming from Unity, so I haven’t done much in C++, except some Workshops, but they was only in C.
My current status is, that I can see the other “Blue Guys” walking arround etc., but the Bullets can only be seen, if the Server is spawning them.
By reading though the Forum I figured out, that the Clients will need to make a RPC to the Server, that they wanna spawn a Bullet.
Now I have read this: https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Replication/RPCs/index.html.
So I wrote this in the Character.h(under TouchStarted):


UFUNCTION(Server,Reliable, WithValidation);
void CreateBullet(const FRotator rot, const FVector loc);

And this in the Character.cpp:


bool CreateBullet _Validate(const FRotator rot, const FVector loc) {
        //I Guess here I can check, if they Delay since last shoot is over, or?
	return true;
}
void CreateBullet _Implementation(const FRotator rot, const FVector loc) {
	UWorld* const World = GetWorld();
	if (World != NULL)
	{
		// spawn the projectile at the muzzle
		AActor* theActor = World->SpawnActor<AMyProject2Projectile>(ProjectileClass, loc, rot);



	}

}

And in the OnFire Void I wrote this:


if (ProjectileClass != NULL)
	{
		const FRotator SpawnRotation = GetControlRotation();
		// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
		const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset);

		CreateBullet(SpawnRotation, SpawnLocation);
	}
...]

In the cpp the _Validate and _Implementation are red underlined as well some other Words…
If I try to build it tells me:


Fehler	1	error : In MyProject2Character: Missing event name	D:\Unreal Projects\SimpleBPShooter\MyProject2\Source\MyProject2\Public\MyProject2Character.h	48	1	MyProject2
Fehler	2	error code: 2	D:\Unreal Projects\SimpleBPShooter\MyProject2\Intermediate\ProjectFiles\Error	MyProject2

Line 48 is this:


UFUNCTION(Server,Reliable, WithValidation);

I don’t know if I even cast the RPG correct, cuz this is not standing in the Docs, but as it seems like the error is somewhere else…

It would be great, if you could help me :).

By the way I have Version 4.5.1

Fixxed it(need to remove the ; after UFunction ^^)

Now it is working like I hoped, but the Rotation is not working(everyone is shooting in 1 Directions, which never changes) (The Location stuff is working)
My current code(OnFire Void):


void AMyProject2Character::OnFire()
{
	// try and fire a projectile
	if (ProjectileClass != NULL)
	{
		

		const FRotator SpawnRotation = FirstPersonCameraComponent->RelativeRotation; //Dunno where I should get rotation otherwise :/
		// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
		const FVector SpawnLocation = CapsuleComponent->GetComponentLocation() + SpawnRotation.RotateVector(GunOffset);

		CreateBullet(SpawnRotation, SpawnLocation);
		
	}

I can see why everyone keeps shooting in one direction: you’re using the camera’s relative rotation but the camera does not rotate with respect to its parent at all! See it like this: the player rotates, but the camera is just ‘lifting’ along. You need the camera’s world rotation.

Try using the PlayerCameraManager. Cast your character’s controller to a player controller and access the active camera’s rotation (in this case will be the same as your FirstPersonCamera, but this works more general):



const APlayerController * PC = Cast<APlayerController>(GetController());
if (!PC) return; // Not a player
const FRotator CamRotation = PC->PlayerCameraManager->GetCameraRotation();


Need to say some words…

This Engine is so confusing there is Pawn, Projectile Movement, PlayerCameraManager, Actor, Character…(This doesn’t make it easier - you don’t know what when to use) Why couldn’t they just make it easy and logical like in Unity… in Unity I had my FPS in 2 hours without experience(and there was(and still there are) a lot of Tutorials - In Unreal Engine there are the official Tutorials, which mostly are for Blueprint and a couple of unofficial Blogs & Tutorials , but who do a Game entirely in Blueprint this is absolutely not necessary)…

I needed 5 hours for walking and shooting
1 hour - that I need to remove Inital Velocity in Local Space
30 Minutes for this Forum
2 hour figuring out how to make a RPC and CALL it(thinked I need something special)
2 hour for other problems

15 Minutes coding

Something is wrong here

@NisshokuZK thank you for your help would never found it out, without your post - now I will try to improve and extend it :slight_smile: