Hi All
I’m finding that while my SplineMeshComponent responds to OnBeginCursorOver, OnEndCursorOver and OnClicked etc events in the PIE mode, this doesn’t work in packaged builds. I have seen this issue both in 4.8.3 and now in 4.9.2. I’ve based the code heavily on https://answers.unrealengine.com/questions/174108/can-you-give-me-an-example-of-splinemeshcomponent-1.html and I note that in this thread at the end, shpen alludes to a similar problem. I list my code below. In order to reproduce, build and run within the editor - this works - the cursor changes to a hand on mouseover. Then package the project, and you should see that this doesn’t work.
Here’s the code:
First MyActor.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "MouseTest.h"
#include "MyActor.h"
// Sets default values
AMyActor::AMyActor()
{
// 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;
SplineComp = CreateDefaultSubobject<USplineComponent>(TEXT("SplineComp"));
mSplineMeshComponent = CreateDefaultSubobject<USplineMeshComponent>(TEXT("SplineMeshComp"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> MyMesh1(TEXT("StaticMesh'/Game/Meshes/flat.flat'"));
MyMesh = MyMesh1.Object;
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
if (GetWorld())
{
mSplineMeshComponent->SetMobility(EComponentMobility::Static);
TArray< FVector > Points;
Points.Add(FVector(0, 0, 0));
Points.Add(FVector(100, 0, 0));
Points.Add(FVector(100, 100, 0));
Points.Add(FVector(0, 100, 0));
Points.Add(FVector(0, 0, 0));
SplineComp->SetSplineWorldPoints(Points);
DrawSpline();
RootComponent = SplineComp;
mSplineMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
mSplineMeshComponent->SetCollisionProfileName(TEXT("BlockAll"));
}
}
// Called every frame
void AMyActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void AMyActor::BlockClicked(UPrimitiveComponent* ClickedComp)
{
if (GEngine)
{
FString message1 = TEXT("BlockClicked Called...");
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, message1);
}
}
void AMyActor::BlockBeginMouseOver(UPrimitiveComponent* ClickedComp)
{
if (GEngine)
{
FString message = TEXT("BlockBeginMouseOver Called...");
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, message);
APlayerController* MyController = GetWorld()->GetFirstPlayerController();
MyController->CurrentMouseCursor = EMouseCursor::Hand;
}
}
void AMyActor::BlockEndMouseOver(UPrimitiveComponent* ClickedComp)
{
if (GEngine)
{
FString message = TEXT("BlockEndMouseOver Called...");
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, message);
APlayerController* MyController = GetWorld()->GetFirstPlayerController();
MyController->CurrentMouseCursor = MyController->DefaultMouseCursor;
}
}
void AMyActor::OnFingerPressedBlock(ETouchIndex::Type FingerIndex, UPrimitiveComponent* TouchedComponent)
{
if (GEngine)
{
BlockClicked(TouchedComponent);
}
}
void AMyActor::DrawSpline()
{
//https://answers.unrealengine.com/questions/174108/can-you-give-me-an-example-of-splinemeshcomponent-1.html
if (GetWorld()){
int nspline = SplineComp->GetNumberOfSplinePoints();
for (int i = 0; i < nspline -1 ; i++){
USplineMeshComponent* SplineMesh = ConstructObject<USplineMeshComponent>(USplineMeshComponent::StaticClass(), this);
SplineMesh->SetStartScale(FVector2D(.25, .25));
SplineMesh->SetEndScale(FVector2D(.25, .25));
FVector pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd;
SplineComp->GetLocalLocationAndTangentAtSplinePoint(i, pointLocationStart, pointTangentStart);
SplineComp->GetLocalLocationAndTangentAtSplinePoint(i + 1, pointLocationEnd, pointTangentEnd);
SplineMesh->SetStartAndEnd(pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd);
SplineMesh->CreationMethod = EComponentCreationMethod::UserConstructionScript;
SplineMesh->SetMobility(EComponentMobility::Movable);
SplineMesh->AttachParent = mSplineMeshComponent;
SplineMesh->bCastDynamicShadow = false;
SplineMesh->SetStaticMesh(MyMesh);
//SplineMesh->SetMaterial(0, ContGlowMaterial_Dyn);
SplineMesh->OnBeginCursorOver.AddDynamic(this, &AMyActor::BlockBeginMouseOver);
SplineMesh->OnEndCursorOver.AddDynamic(this, &AMyActor::BlockEndMouseOver);
SplineMesh->OnClicked.AddDynamic(this, &AMyActor::BlockClicked);
SplineMesh->OnInputTouchBegin.AddDynamic(this, &AMyActor::OnFingerPressedBlock);
SplineMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
SplineMesh->SetCollisionProfileName(TEXT("BlockAll"));
//SplineMesh->SetCollisionResponseToChannel(ECC_Visibility, ECollisionResponse::ECR_Block);
//SplineMesh->SetCollisionProfileName(TEXT("UI"));
SplineMeshComponents.Add(SplineMesh);
}//i
RegisterAllComponents();
}
}
and MyActor.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Components/SplineComponent.h"
#include "Components/SplineMeshComponent.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class MOUSETEST_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
/** StaticMesh component */
UPROPERTY(Category = Block, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* BlockMesh;
UFUNCTION(BlueprintCallable, Category = MeshTest)
void BlockClicked(UPrimitiveComponent* ClickedComp);
UFUNCTION(BlueprintCallable, Category = MeshTest)
void BlockBeginMouseOver(UPrimitiveComponent* ClickedComp);
UFUNCTION(BlueprintCallable, Category = MeshTest)
void BlockEndMouseOver(UPrimitiveComponent* ClickedComp);
UFUNCTION(BlueprintCallable, Category = MeshTest)
void OnFingerPressedBlock(ETouchIndex::Type FingerIndex, UPrimitiveComponent* TouchedComponent);
UPROPERTY(EditAnywhere, Category = MeshImport)
USplineComponent *SplineComp;
UPROPERTY(EditAnywhere, Category = MeshImport)
USplineMeshComponent *mSplineMeshComponent;
UPROPERTY(EditAnywhere, Category = MeshImport)
UStaticMesh *MyMesh;
TArray<USplineMeshComponent*> SplineMeshComponents;
void DrawSpline();
};
More likely to be something I’m not doing correctly than a bug, but I’d be glad of any help on this.
Many Thanks in advance.