Trying to wrap my head around this delegate stuff, and I have to say it’s rather confusing. I am trying to copy the functionality from the Multiplayer shootout in C++.
I have my own player controller defined, and within there I am defining a delegate.
Infantry_RebornPlayerController.h:
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/PlayerController.h"
#include "Infantry_RebornPlayerController.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FClientPostLoginDelegate);
UCLASS()
class AInfantry_RebornPlayerController : public APlayerController
{
GENERATED_BODY()
public:
AInfantry_RebornPlayerController();
UPROPERTY(BlueprintAssignable)
FClientPostLoginDelegate ClientPostLogin;
protected:
void RotateToMouseCursor(float DeltaTime);
// Begin PlayerController interface
virtual void PlayerTick(float DeltaTime) override;
// End PlayerController interface
/* Player movement */
float yawSpeed = 5.0f;
void OnClientPostLogin();
};
Infantry_RebornPlayerController.cpp:
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "Infantry_Reborn.h"
#include "Infantry_RebornPlayerController.h"
AInfantry_RebornPlayerController::AInfantry_RebornPlayerController()
{
bShowMouseCursor = true;
bEnableClickEvents = true;
bEnableMouseOverEvents = true;
ClientPostLogin.Add(&AInfantry_RebornPlayerController::OnClientPostLogin);
}
void AInfantry_RebornPlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);
this->RotateToMouseCursor(DeltaTime);
}
void AInfantry_RebornPlayerController::RotateToMouseCursor(float DeltaTime) {
FHitResult Hit;
GetHitResultUnderCursor(ECC_Visibility, false, Hit);
if (Hit.Actor != nullptr) {
// Get local reference to the controller's character and its rotation
ACharacter *currentChar = this->GetCharacter();
if (currentChar != NULL) {
FRotator charRotation = currentChar->GetActorRotation();
// Get the rotation of the mouse direction
FVector TargetVector = Hit.ImpactPoint - currentChar->GetActorLocation();
TargetVector.Normalize();
FRotator targetRot = FRotator(charRotation.Pitch, TargetVector.Rotation().Yaw, charRotation.Roll);
FRotator newRot = FMath::RInterpTo(this->GetControlRotation(), targetRot, DeltaTime, this->yawSpeed);
// Since I only want to turn the character relative to the ground,
// the Yaw is the only change needed.
this->ControlRotation = newRot;
currentChar->SetActorRotation(newRot);
}
}
}
void AInfantry_RebornPlayerController::OnClientPostLogin()
{
this->SetupInGameUI();
}
But when I compile I get:
Error 1 error C2664: ‘void TMulticastScriptDelegate::Add(const TScriptDelegate &)’ : cannot convert argument 1 from ‘void (__cdecl AInfantry_RebornPlayerController::* )(void)’ to ‘const TScriptDelegate &’ C:\Users\Documents\Unreal Projects\Infantry_Reborn\Source\Infantry_Reborn\Infantry_RebornPlayerController.cpp 12 1 Infantry_Reborn
I have read several sources online that just don’t match up with what is currently in the engine (Bind does not exist, AddDynamic does not exist, the only one I see is Add and it doesn’t work for me).