Hello & thanks in advance! I have a C++ derived actor with SceneComponent, StaticMeshComponent from a parent class. Both are set to EditAnywhere, BlueprintReadWrite (Public section of class).
I’m trying to attach a widget component to this actorclass (have tried it in the parent class) with the following code. For the life of me - this will not render in playmode. Going to wireframe you dont see the blue widget card it should be sitting on above the actor. It does show it created and you can break out of play and select the widget - its location is directly above the actor… so its in the right place but not being created right. What am I doing wrong?
SCREENSHOT:
http://puu.sh/ptCss/9dee55926d.jpg
.h
#pragma once
#include "WidgetComponent.h"
#include "PickupItem.generated.h"
/**
*
*/
UCLASS()
class MYPROJECT_API APickupItem : public AInteractable
{
GENERATED_BODY()
public:
APickupItem();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pickup Properties")
USceneComponent* SceneComponent;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "PickupProperties")
class UWidgetComponent* PickupWidget;
.cpp
#include "MyProject.h"
#include "PickupItem.h"
#include "MyProjectCharacter.h"
APickupItem::APickupItem()
{
// Setup SceneCOmponent & Set as root
SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComp"));
RootComponent = SceneComponent;
//SetUp the mesh for the pickup ,item name, help text & Item value
InteractableMesh = CreateDefaultSubobject <UStaticMeshComponent>(TEXT("PickupMesh"));
InteractableMesh->SetSimulatePhysics(true);
InteractableMesh->AttachTo(RootComponent);
PickupWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("Widget"));
PickupWidget->SetWidgetSpace(EWidgetSpace::World);
PickupWidget->SetRelativeLocation(FVector(0, 0, 50), false, nullptr, ETeleportType::None);
PickupWidget->SetMaxInteractionDistance(1000.f);
PickupWidget->SetPivot(FVector2D(.5f, .5f));
PickupWidget->AttachTo(SceneComponent);
PickupWidget->SetVisibility(true);
PickupWidget->RegisterComponent();