hey here.
Am encourtering a really strange bug which I can’t seem to understand. I have a pickup actor which I stack in an inventory. It has a spherecomponent and a staticmesh component, so far so good. But When I include a Widget Component, it makes the compile fail.
PickUpItem.cpp:
#include "PickUpItem.h"
#include "Components/SphereComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Blueprint/UserWidget.h"
#include "Components/WidgetComponent.h"
#include "UObject/ConstructorHelpers.h"
#include "BkPcsPlayerController.h"
#include "BkPcsCharacter.h"
// Sets default values
APickUpItem::APickUpItem()
{
PrimaryActorTick.bCanEverTick = true; //TODO verify if it's necessary
Name = "Name not set";
Action = "Interact";
ItemID = FName("Please enter an ID");
BaseCollisionComponent = CreateDefaultSubobject<USphereComponent>(FName("BaseSphereComponent")); // Create the root CapsuleComponent to handle the pickup's collision
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(FName("PickupMesh")); //Create the static mesh component
if (!ensure(BaseCollisionComponent != nullptr)) return;
if (!ensure(PickupMesh != nullptr)) return;
RootComponent = BaseCollisionComponent; // Set the SphereComponent as the root component.
PickupMesh->SetSimulatePhysics(false); // Start with physics simulation disabled, for easy manipulation on UE4 Editor.
const FAttachmentTransformRules &AttachmentRules = FAttachmentTransformRules::SnapToTargetNotIncludingScale;
PickupMesh->AttachToComponent(RootComponent, AttachmentRules);
The3DWidget = CreateDefaultSubobject<UWidgetComponent>(FName("3DWidget"));
PickupMesh->AttachToComponent(RootComponent, AttachmentRules);
static ConstructorHelpers::FClassFinder<UUserWidget> WidgetBPRef(TEXT("/Game/BluePrint/HUD/WG_PickUps3D"));
The3DWidget->SetWidgetSpace(EWidgetSpace::Screen);
The3DWidget->SetWidgetClass(WidgetBPRef.Class);
BaseCollisionComponent->bGenerateOverlapEvents = true; // Enable the generation of overlapping events and assign a function to be run when it happens.
PickupMesh->bGenerateOverlapEvents = false; // Disable Overlap Events on the Mesh
}
PickupItem.h (simplified)
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "PickUpItem.generated.h"
class USphereComponent;
class UStaticMeshComponent;
class UWidgetComponent;
/**
*
*/
UCLASS()
class BROKENPIECES_API APickUpItem : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly)
FString Name;
UPROPERTY(EditDefaultsOnly)
FString Action;
UFUNCTION(BlueprintCallable, Category = "PickUps")
FName GetItemID() { return ItemID; }
UPROPERTY(VisibleAnywhere, Category = "PickUps")
USphereComponent* BaseCollisionComponent;
/** StaticMeshComponent to represent the pickup in the level */
UPROPERTY(VisibleAnywhere, Category = "PickUps")
UStaticMeshComponent* PickupMesh;
UPROPERTY(VisibleAnywhere, Category = "PickUps")
UWidgetComponent* The3DWidget;
};
It seems like the game suddently when am adding a widgetcomponent expect my class to be an uobject, thus whithout beginplay() etc.
If anyone can tell me what stupid mistake I am doing, this would be of great help.
Thanks a bunch !