Hi Everyone!
I know this must be a really stupid question but i couldn’t find the solution. If this is a duplicate question, please link me the answer.
The problem is:
I made an actor called PickupItem
UCLASS()
class PROJECT_API APickupItem : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
APickupItem();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
FString Name;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
int32 Quatity;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
USphereComponent* ProxSphere;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
UStaticMeshComponent* Mesh;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
UTexture2D* Icon;
UFUNCTION(BlueprintNativeEvent, Category = Collision)
void Prox(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
I made some pickup items from this class that when i walk nearby them, i collect the item.
Now i want a Character to be able to give me the item when i’m close to him. So i made an NPC class
UCLASS()
class PROJECT_API ANPC : public ACharacter
{
GENERATED_BODY()
public:
ANPC();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
USphereComponent* ProxSphere;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
FString NPCMessage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
FString NPCName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
UTexture2D* Face;
UFUNCTION(BlueprintNativeEvent, Category = Collision)
void Prox(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
};
and tried to add
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
APickupItem* Item;
and on the constructor
Item = NewObject<APickupItem>();
And the Unreal Crashes (Even though the project actually compiles)
Also tried with
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
AActor* Item;
But got the same result.
What i’m i doing wrong? i tried searching for something similar but all that i could found was on blueprint and parsing it to c++ didn’t even compile.
Basically what i want to do is to be able to expose those attributes to a blueprint so i can later define then as the item that the player will get.