Could I get some help with some beginner ue4 code questions dealing with Actor component creation?

Hi!

I’m new to ue4 and I have been trying to create my first pickuUp actor and I ran into some trouble. For starters I’m wondering is PCIP.CreateDefaultSubobject the rigth way to create components for actor? Two other questions are related to my code so here is my header file:

UCLASS()
class AGoldPickUp : public AActor
{
	GENERATED_UCLASS_BODY()

	//UPROPERTY()
	TSubobjectPtr<UStaticMeshComponent> meshComp;
	UStaticMesh *mesh;

	//TSubobjectPtr<UParticleSystemComponent> effectCom;

	private:
		void setUpMesh(UStaticMeshComponent *StMeshComp);
		void setMaterial(uint32 matPlace, UStaticMeshComponent *StMeshComp);
};

and here my cpp file:

AGoldPickUp::AGoldPickUp(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshObject(TEXT("StaticMesh'/Game/Props/SM_MatPreviewMesh_02.SM_MatPreviewMesh_02'"));
	mesh = StaticMeshObject.Object;

	//effectCom = PCIP.CreateDefaultSubobject<UParticleSystemComponent>(this, "effect");
	meshComp = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, "oreMesh");

	meshComp->SetStaticMesh(mesh);
	setUpMesh(meshComp);
	setMaterial(0, meshComp);

	RootComponent = meshComp;
	SetActorEnableCollision(true);
	
}

When I uncomment UPROPERTY before meshComp I get following error message when I try to build: 'MeshComp' : is not a member of 'AGoldPickUp' why is this and how to fix it?

When I uncomment effectComp in the headerfile(still works after this) and uncomment effectCom creation in constructor I get error message: cannot convert from 'UParticleSystemComponent *' to 'UObject *' Types pointed to are unrelated.

I have been struggling with this for a while. All answers will be appreciated :slight_smile: Sorry for my partially bad english.

I already found found answer to the UPROPERTY question from answerhub :smiley:
It was capitalization problem renaming meshComp to MeshComp fixed the problem. Other questions still stand :slight_smile:

Try including:

#include "ParticleDefinitions.h"

In your ModuleName.h file (the one that should be in Public folder).

Thank you! :smiley: That fixed the problem.