UWidgetComponent created using C++ not editable in viewport

I raised this as a question here https://answers.unrealengine.com/questions/173632/creating-uwidgetcomponent-using-c.html - but the more I look at it the more it seems like a bug rather than something I’ve done wrong.

I create a new UWidgetComponent on my Character Pawn

AFFCharacter::AFFCharacter(const class FObjectInitializer& PCIP)
	: Super(PCIP.SetDefaultSubobjectClass<UFFCharacterMovement>(ACharacter::CharacterMovementComponentName))
{
	CapsuleHeight = 96.0f;
	CapsuleRadius = 45.0f;
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(CapsuleHeight, CapsuleRadius);
	
	// set our turn rates for input
	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

	// Default offset from the character location for projectiles to spawn
	GunOffset = FVector(100.0f, 30.0f, 10.0f);

	// Create a CameraComponent	
	PlayerCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("PlayerCamera"));
	PlayerCameraComponent->AttachParent = GetCapsuleComponent();
	PlayerCameraComponent->AttachSocketName = FName(TEXT("HeadCameraSocket"));
	//PlayerCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera

	UMeshComponent* PlayerMesh = GetMesh();
	PlayerMesh->SetOnlyOwnerSee(false);			// only the owning player will see this mesh
	PlayerMesh->AttachParent = PlayerCameraComponent;
	PlayerMesh->bCastDynamicShadow = true;
	PlayerMesh->CastShadow = true;

	// Create a first person mesh, so we can switch between first and third person
	FirstPersonMesh = PCIP.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("FirstPersonMesh"));
	FirstPersonMesh->SetOnlyOwnerSee(true);			// only the owning player will see this mesh
	FirstPersonMesh->AttachParent = PlayerCameraComponent;
	FirstPersonMesh->RelativeLocation = FVector(0.f, 0.f, -150.f);
	FirstPersonMesh->bCastDynamicShadow = false;
	FirstPersonMesh->CastShadow = false;

	// Create a component for doing a 3d pointer to the source of the damage
	DamageSourceWidget = PCIP.CreateDefaultSubobject<UWidgetComponent>(this, TEXT("DamageSource"));
	DamageSourceWidget->SetOnlyOwnerSee(true);
	DamageSourceWidget->AttachParent = PlayerCameraComponent;
	DamageSourceWidget->RelativeLocation = FVector(220.0f, -50.0f, 0.0f);
	DamageSourceWidget->RelativeRotation = FRotator(40.0f, 0.0f, 90.0f);

	// Set that we allow crouching in this game
	GetCharacterMovement()->GetNavAgentProperties()->bCanCrouch = true;

	// Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P are set in the
	// derived blueprint asset named MyCharacter (to avoid direct content references in C++)
	WallRunInitialClimbSpeed = 200;
	WallRunGravityScale = 0.5;

	Health = 100;
	DamageScaling = 1.0f;

	DoubleTapToDiveTime = 0.5f;

}

The result is that the widget is not editable in the unreal engine editor

https://dl.dropboxusercontent.com/s/b059fhas9f8h9z6/broken-widget.PNG?dl=0

When using the unreal engine editor to add a widget, the details panel has all the stuff I want to edit

https://dl.dropboxusercontent.com/s/qg8e8ryfqmuv0as/expected-widget.PNG?dl=0

Hi GeekyPayback,

Would it be possible to see the lines in your header file where you declare DamageSourceWidget? I was able to reproduce what you are seeing, but only by not declaring DamageSourceWidget as a UPROPERTY.

I didn’t set a UProperty, so that’s likely to be the cause. Here is my declaration up to the DamageSourceWidget. Does it just need to be an empty UProperty or are parameters required?

UCLASS(config=Game)
class AFFCharacter : public ACharacter, public IMinimapInterface
{
	GENERATED_UCLASS_BODY()

	/** Pawn mesh: 1st person view (arms; seen only by self) */
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Mesh)
	class USkeletalMeshComponent* FirstPersonMesh;

	/** Cached FFCharacterMovement casted CharacterMovement */
	UPROPERTY(Category = Character, VisibleAnywhere, BlueprintReadOnly)
	class UFFCharacterMovement* FFCharacterMovement;


	/** Third person camera */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
	class UCameraComponent* PlayerCameraComponent;

	/** Damage location UMG Widget */
	class UWidgetComponent* DamageSourceWidget;

For a variable/component in a class to be available in a Blueprint, you will need to add a UPROPERTY. Unfortunately just a blank UPROPERTY() won’t be sufficient. Depending on how much you need to be able to edit here, there are a few options. UPROPERTY(EditDefaultsOnly) will make most of the properties available to be edited in the Blueprint Editor. If you want to be able to edit all of the properties, you would want to use UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite).

I went with UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = HUD) and I can edit it all now. I’ll re-test whether this fixes the in-game rendering too, and raise another bug if not. Thanks for your help

Newbie to Unreal here, What do you include to get this to compile?

Well, while trying this out I ran into a problem:

.h

#include "WidgetComponent.h"

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Nameplate)
class UWidgetComponent* NameplateWidget;

.cpp (constructor)

NameplateWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("NameplateWidgetComponent"))

This crashes the 4.8.1 editor every time when starting it.

Only commenting the line in the .cpp stops the editor from crashing.

Hi ,

Do you still see this happening in 4.8.2? If so, please submit a new post about the issue, and we will focus on it there.

Sorry for the late response. That seems to be fine now.