How to set a Billboard Sprite on a class extending from SceneComponent?
Here is my constructor, this doesn’t work.
UAmmoMarker::UAmmoMarker(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
bWantsInitializeComponent = true;
PrimaryComponentTick.bCanEverTick = true;
// Structure to hold one-time initialization
struct FConstructorStatics
{
// A helper class object we use to find target UTexture2D object in resource package
ConstructorHelpers::FObjectFinderOptional<UTexture2D> NoteTextureObject;
// Icon sprite category name
FName ID_CatagoryName;
// Icon sprite display name
FText NAME_DisplayName;
FConstructorStatics()
// Use helper class object to find the texture
// "/Engine/EditorResources/S_Note" is resource path
: NoteTextureObject(TEXT("/Game/Blueprints/icons/AmmoMarker"))
, ID_CatagoryName(TEXT("Marker"))
, NAME_DisplayName(NSLOCTEXT("SpriteCategory", "AmmoMarker", "AmmoMarker"))
{
}
};
static FConstructorStatics ConstructorStatics;
#if WITH_EDITORONLY_DATA
//SpriteComponent = ObjectInitializer.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(this, TEXT("Sprite"));
if (SpriteComponent)
{
SpriteComponent->Sprite = ConstructorStatics.NoteTextureObject.Get(); // Get the sprite texture from helper class object
SpriteComponent->SpriteInfo.Category = ConstructorStatics.ID_CatagoryName; // Assign sprite category name
SpriteComponent->SpriteInfo.DisplayName = ConstructorStatics.NAME_DisplayName; // Assign sprite display name
SpriteComponent->AttachParent = this; // Attach sprite to scene component
SpriteComponent->Mobility = EComponentMobility::Static;
}
#endif // WITH_EDITORONLY_DATA