# UWIDGETCOMPONENT - Does not get created for C++ actor

**URL:** <https://forums.unrealengine.com/t/uwidgetcomponent-does-not-get-created-for-c-actor/360866>\
**Category:** UI\
**Tags:** unreal-engine, Widget, CPP, question\
**Created:** [June 15, 2016, 2:00pm UTC](https://forums.unrealengine.com/t/uwidgetcomponent-does-not-get-created-for-c-actor/360866 "2016-06-15T14:00:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![walldiv](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@walldiv](https://forums.unrealengine.com/u/walldiv)\
**Post date:** [June 15, 2016, 2:00pm UTC](https://forums.unrealengine.com/t/uwidgetcomponent-does-not-get-created-for-c-actor/360866/1 "2016-06-15T14:00:01Z")

</div>

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](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();
```

---

<div class="post-metadata">

**Author:** ![walldiv](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@walldiv](https://forums.unrealengine.com/u/walldiv)\
**Post date:** [June 15, 2016, 3:47pm UTC](https://forums.unrealengine.com/t/uwidgetcomponent-does-not-get-created-for-c-actor/360866/2 "2016-06-15T15:47:39Z")

</div>

UpdateRenderTarget(); This makes it appear in the world.

However it is still rendering as invisible. . . . yet the card it lies on shows up when you go to wireframe mode in editor - played mode.

---

<div class="post-metadata">

**Author:** ![walldiv](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@walldiv](https://forums.unrealengine.com/u/walldiv)\
**Post date:** [June 15, 2016, 7:31pm UTC](https://forums.unrealengine.com/t/uwidgetcomponent-does-not-get-created-for-c-actor/360866/3 "2016-06-15T19:31:52Z")

</div>

Solved:

FIRSTLY - i was informed that custom constructors are taboo… and switching to class:class(const FObjectInitializer& OI) : Super(OI) seemed to fix everything! Below is the stuff to make DetailsPane selectable widget - and store it as the widget class for the components use. the .cpp draws it just fine but requires Super::BeginPlay()

.h  
UPROPERTY(EditAnywhere, Category = “Pickup Properties”)  
TSubclassOf PickupWidgetClass;  
UPROPERTY(EditDefaultsOnly, Category = “PickupProperties”)  
UMyWidgetBlueprint\* Active\_PickupWidgetClass;

.cpp  
PickupWidget-\>SetWidgetClass(PickupWidgetClass);

void APickupItem::BeginPlay()  
{  
Super::BeginPlay();  
}

---

<div class="post-metadata">

**Author:** ![jeevcat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jeevcat](https://forums.unrealengine.com/u/jeevcat)\
**Post date:** [May 17, 2017, 12:39pm UTC](https://forums.unrealengine.com/t/uwidgetcomponent-does-not-get-created-for-c-actor/360866/4 "2017-05-17T12:39:15Z")

</div>

I’m having the same problem you faced. However, changing the constructor type didn’t fix this issue.

Since when are constructors with no parameters taboo? According to [this](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Classes/#classconstructor), the ObjectInitializer version is just another option, which gives you a little more flexibility.
