Help: No option for Projectile Mesh in defaults

I’m not sure what’s missing as there are no errors, but DefaultSceneRoot is attached to my BP_Projectile(self) and not a static mesh. There were no issues before adding #include “Components/StaticMeshComponent.h”, and it seems as if I also left it out in my BasePawn.cpp however everything else has worked as expected so far.

I tried recompiling after adding the Static Mesh header but that still hasn’t fixed it.

Projectile.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Projectile.generated.h"

UCLASS()
class TOONTANKS_API AProjectile : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AProjectile();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

private:
	UPROPERTY(EditDefaultsOnly, Category = "Combat")
	UStaticMeshComponent* ProjectileMesh;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

};

Projectile.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "Projectile.h"
#include "Components/StaticMeshComponent.h"

// Sets default values
AProjectile::AProjectile()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;

}

// Called when the game starts or when spawned
void AProjectile::BeginPlay()
{
	Super::BeginPlay();

	ProjectileMesh = CreateDefaultSubobject <UStaticMeshComponent> (TEXT("Projectile Mesh"));
	RootComponent = ProjectileMesh;	
}

// Called every frame
void AProjectile::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

This should be in the constructor not BeginPlay

Thanks, I had a feeling I was missing something obvious

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms