Is there someone I could talk to about getting OnBeginCursorOver to work in my Prototype? I recently learned C++, so I’m fairly new with the language, and I’m still trying to break down UE4’s API. I’m trying to implement OnBeginCursorOver on some of my actors. I have a player controller setup with MouseOverEvents enabled. The actors that I’m trying to interact with are customer actors that I’m spawning, so perhaps I could be missing something important when I build them.
Here’s my code below where I’m calling OnBeginCursorOver, again, kinda new to C++ and the UE4 API, so excuse my crappy prototype code,
.h
#pragma once
#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “InteractiveInterface.h”
#include “GridTile.generated.h”
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class AI_PROTOTYPE02_API AGridTile : public AActor, public IInteractiveInterface
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
AGridTile();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* BoxVisual;
UMaterialInterface* material;
UMaterialInstanceDynamic* DynamicMaterial;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void SetColor(FLinearColor color);
**void BeginCursorOver(AActor* Actor);**
};
.cpp
#include “UObject/ConstructorHelpers.h”
#include “Components/BoxComponent.h”
#include “GridTile.h”
// Sets default values
AGridTile::AGridTile()
{
// 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;
RootComponent = BoxVisual;
BoxVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> BoxVisualAsset(TEXT("StaticMesh'/Game/Textures/ST_Box_Brush_StaticMesh.ST_Box_Brush_StaticMesh'"));
if (BoxVisualAsset.Succeeded())
{
BoxVisual->SetStaticMesh(BoxVisualAsset.Object);
BoxVisual->SetWorldScale3D(FVector(1.0f));
}
BoxVisual->SetCollisionProfileName(TEXT("BlockAllDynamic"));
}
// Called when the game starts or when spawned
void AGridTile::BeginPlay()
{
Super::BeginPlay();
material = BoxVisual->GetMaterial(0);
DynamicMaterial = UMaterialInstanceDynamic::Create(material, this);
BoxVisual->SetMaterial(0, DynamicMaterial);
**this->OnBeginCursorOver.AddDynamic(this, &AGridTile::BeginCursorOver);**
}
// Called every frame
void AGridTile::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AGridTile::SetColor(FLinearColor color)
{
DynamicMaterial->SetVectorParameterValue(TEXT(“ColorOfTile”), color);
}
void AGridTile::BeginCursorOver(AActor Actor)*
{
** GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, “Step 2”);**
}