4.5 UStruct Replication

So I am currently making a crude login system for my game. If anyone knows of an easier or better way let me know. Here’s my current system, my PlayerController contains a UStruct called FLoginSystem that i’m using to handle my login variables. In my GameMode, i have a timer that checks though the list of PlayerControllers and see if the UStruct variable TryLogin is true and if so check a userlist file to authenticate the username and password. Then if the username and password is valid or not, set the UStruct variables LoginFailed and LoggedIn.

My Problem:
Either I am doing this completely wrong or I am missing a step, but I keep getting the annoying vs syntax error for the DOREPLIFETIME in AMyPlayerController::GetLifetimeReplicatedProps. Am I missing a header? or am I missing a simple step. I have looked at Rama’s UStruct tutorial, but still can’t seem to get it right.

My Code:
AMyPlayerController.h

#pragma once

#include "GameFramework/PlayerController.h"

#include "MyPlayerController.generated.h"

/**
 * 
 */

USTRUCT(BlueprintType)
struct FLoginSystem
{
	GENERATED_USTRUCT_BODY()

	// Player Login Info
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LoginInfo")
		FString Username;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LoginInfo")
		FString Password;

	// Player States
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayerStates")
		bool TryLogin;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayerStates")
		bool LoginFailed;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayerStates")
		bool LoggedIn;
};

UCLASS()
class TARRAGON_API AMyPlayerController : public APlayerController
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(Replicated, RepRetry)
	class FLoginSystem PlayerLoginSystem;
};

AMyPlayerController.cpp

#include "Tarragon.h"
#include "MyPlayerController.h"


AMyPlayerController::AMyPlayerController(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	PlayerLoginSystem.TryLogin = false;
	PlayerLoginSystem.LoginFailed = false;
	PlayerLoginSystem.LoggedIn = false;
}

void AMyPlayerController::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DORREPLIFETIME(AMyPlayerController, PlayerLoginSystem);
}

#Add Net Header

//Network Code
#include "Net/UnrealNetwork.h"

make your header this!

#pragma once

//Network Code
#include "Net/UnrealNetwork.h"

 #include "GameFramework/PlayerController.h"
 
 #include "MyPlayerController.generated.h"

Now it will work!

#:)

Rama

Thank you! It gets rid of all the errors :). Now another problem I am now having is trying to view my replicated variable through blueprints so I can see them. I tried adding BlueprintCallable, but it errors out at me. Can you not blueprint replicated variables? or must you create a pointer to them?

BlueprintCallable is a UFUNCTION tag. You probably want BlueprintReadOnly or BlueprintReadWrite

Ugh Dumb moment xD. One more noob question… I now set UStruct through in blueprints from getting the owning player and casting to my playerController. However when my server loops to see who is trying to login. It is still receiving null values for everything. Am I getting the current playercontrollers correctly that are connected to the game?

Code:

void AMyGameMode::FindLoggingPlayers()
{
			for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
			{
				AMyPlayerController* player = Cast<AMyPlayerController>(*Iterator);
				FLoginSystem* PlayerLoginInfo = &player->PlayerLoginSystem;
				if (PlayerLoginInfo->TryLogin)
				{
					// if successful tell player to "login"
					if (CanLogin(PlayerLoginInfo->Username, PlayerLoginInfo->Password))
					{
						PlayerLoginInfo->TryLogin = false;
						PlayerLoginInfo->LoggedIn = true;
					}
					// if failed
					else
					{
						PlayerLoginInfo->TryLogin = false;
						PlayerLoginInfo->LoginFailed = true;
					}
				}
			}
}