Hello guys! I have a problems with variables of a Pawn. I have a Pawn where i change different variables and inputs (like a bool variable of left click mouse). I have a Static Mesh actor. I want to interact with actor using variables from my Pawn. I tried to cast it with my pawn, but when i trying to get access to my variable my project crashes. (Also i know that in blueprint cast node is easy to use. In blueprint we can make a actor reference variable. but in C++ there is nothing like that I think).
#include "BuildYourOwnClassC.h"
#include "ObjectTemplate.h"
#include "CursorPawn.h"
// Sets default values
AObjectTemplate::AObjectTemplate()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
MyMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));
}
// Called when the game starts or when spawned
void AObjectTemplate::BeginPlay()
{
Super::BeginPlay();
ACursorPawn* MyPC = Cast<ACursorPawn>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
if (MyPC->bRMB) {
UE_LOG(LogTemp, Warning, TEXT("IT WORKS! (of course it doesn't:( )"))
}
}
// Called every frame
void AObjectTemplate::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
Help pls! How can I connect my CursorPawn with this actor??