Hello everyone,
I’m fairly new to C++ in general so I might just do something stupidly wrong.
As said, I’m trying to create an actor with a sprite to be able to place it in the scene.
After that I will try to display the text of the actor in a 2d caption to give more info about what’s displayed and a link between the text and the position of the object.
I pretty much copied the code of a Note and included the “BillboardComponent.h” and the “Components/ArrowComponent.h”.
It will be easier with the code so here is the header :
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Actor.h"
#include "Components/BillboardComponent.h"
#include "Components/ArrowComponent.h"
#include "abbVieAppTooltipActor.generated.h"
UCLASS(hidecategories = (Input), showcategories = ("Input|MouseInput", "Input|TouchInput"))
class ABBVIEAPP_API AabbVieAppTooltipActor : public AActor
{
GENERATED_UCLASS_BODY()
//virtual void BeginPlay() OVERRIDE;
#if WITH_EDITORONLY_DATA
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Note, meta = (MultiLine = "true"))
FString Text;
// Reference to sprite visualization component
private_subobject :
UPROPERTY()
class UBillboardComponent* SpriteComponent;
UPROPERTY()
class UArrowComponent* ArrowComponent;
#endif // WITH_EDITORONLY_DATA
public:
UPROPERTY(EditAnywhere)
AActor* CameraLink;
#if WITH_EDITORONLY_DATA
/** Returns SpriteComponent subobject **/
ENGINE_API class UBillboardComponent* GetSpriteComponent() const;
/** Returns ArrowComponent subobject **/
ENGINE_API class UArrowComponent* GetArrowComponent() const;
#endif
};
And here is the cpp :
// Fill out your copyright notice in the Description page of Project Settings.
#include "abbVieApp.h"
#include "abbVieAppTooltipActor.h"
AabbVieAppTooltipActor::AabbVieAppTooltipActor(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
USceneComponent* SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComp"));
RootComponent = SceneComponent;
RootComponent->Mobility = EComponentMobility::Static;
#if WITH_EDITORONLY_DATA
ArrowComponent = CreateEditorOnlyDefaultSubobject<UArrowComponent>(TEXT("Arrow"));
SpriteComponent = CreateEditorOnlyDefaultSubobject<UBillboardComponent>(TEXT("Sprite"));
if (!IsRunningCommandlet())
{
// Structure to hold one-time initialization
struct FConstructorStatics
{
ConstructorHelpers::FObjectFinderOptional<UTexture2D> SpriteTexture;
FName ID_Tooltips;
FText NAME_Tooltips;
FConstructorStatics()
: SpriteTexture(TEXT("/Engine/EditorResources/S_Note"))
, ID_Tooltips(TEXT("Tooltips"))
, NAME_Tooltips(NSLOCTEXT("SpriteCategory", "Notes", "Notes"))
{
}
};
static FConstructorStatics ConstructorStatics;
if (ArrowComponent)
{
ArrowComponent->ArrowColor = FColor(150, 200, 255);
ArrowComponent->ArrowSize = 0.5f;
ArrowComponent->bTreatAsASprite = true;
ArrowComponent->SpriteInfo.Category = ConstructorStatics.ID_Tooltips;
ArrowComponent->SpriteInfo.DisplayName = ConstructorStatics.NAME_Tooltips;
ArrowComponent->Mobility = EComponentMobility::Static;
}
if (SpriteComponent)
{
SpriteComponent->Sprite = ConstructorStatics.SpriteTexture.Get();
SpriteComponent->SpriteInfo.Category = ConstructorStatics.ID_Tooltips;
SpriteComponent->SpriteInfo.DisplayName = ConstructorStatics.NAME_Tooltips;
SpriteComponent->SetupAttachment(RootComponent);
SpriteComponent->bIsScreenSizeScaled = true;
SpriteComponent->Mobility = EComponentMobility::Static;
//SpriteComponent->bVisible = true;
//SpriteComponent->bAbsoluteScale = true;
}
}
#endif // WITH_EDITORONLY_DATA
bHidden = false;
bCanBeDamaged = false;
}
// Called every frame
/*
void AabbVieAppTooltipActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}*/
#if WITH_EDITORONLY_DATA
/** Returns SpriteComponent subobject **/
UBillboardComponent* AabbVieAppTooltipActor::GetSpriteComponent() const { return SpriteComponent; }
/** Returns ArrowComponent subobject **/
UArrowComponent* AabbVieAppTooltipActor::GetArrowComponent() const { return ArrowComponent; }
#endif
I already googled and looked everywhere but the solutions to add a sprite for an actor are usually outdated or not the way I want.
Thanks for trying to help 