x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Can't compile with Widget Component

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 !

Product Version: UE 4.18
Tags:
more ▼

asked Mar 27 '18 at 06:38 PM in C++ Programming

avatar image

Elseware-Experience
11 3 3

avatar image Elseware-Experience Apr 02 '18 at 07:50 AM

bump ! Could really use some help here <3

avatar image Elseware-Experience Apr 09 '18 at 09:23 AM

Well, never found an explanation to this. Wondering if I should post it elsewhere.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question