My mesh not showing

I made a pickup class with a rootcomponet but now when I drag my pickup class into the level and make a static mesh but I can’t see the mesh only the sphere here’s my code if it will help

  .h
#include "GameFramework/Actor.h"
#include "pickup.generated.h"

UCLASS()
class MYFIRSTGAME_API Apickup : public AActor
{
	GENERATED_BODY()



public:
	UPROPERTY(visibledefaultsonly, blueprintreadwrite, category = "ammo crate")
		int32 count;
	UPROPERTY(visibledefaultsonly, blueprintreadwrite, category = "ammo crate")
		UShapeComponent*touchsphere;

	UPROPERTY(visibledefaultsonly, blueprintreadwrite, category = "ammo crate")
		UStaticMeshComponent*staticmesh;

		
public:	
	// Sets default values for this actor's properties
	Apickup();


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

	UFUNCTION()
		void onpickup (UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);


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

	
public:
	USceneComponent*pickuproot;


};


 cpp
#include "Myfirstgame.h"
#include "pickup.h"
#include "MyfirstgameCharacter.h"


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

	staticmesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("pickupmesh"));
	staticmesh->AttachToComponent(pickuproot, FAttachmentTransformRules::SnapToTargetIncludingScale);


     touchsphere = CreateDefaultSubobject<USphereComponent>(TEXT("touchsphere"));

	 pickuproot = CreateAbstractDefaultSubobject<USceneComponent>(TEXT("pickuproot"));
	 RootComponent = pickuproot;

	 
	 count = 30;

	 touchsphere->SetWorldScale3D(FVector(1.f, 1.f, 1.f));
	 touchsphere->bGenerateOverlapEvents = true;
	 touchsphere->OnComponentBeginOverlap.AddDynamic(this, &Apickup::onpickup);
	 touchsphere->AttachToComponent(pickuproot, FAttachmentTransformRules::SnapToTargetIncludingScale);	 
}




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

void Apickup::onpickup(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	AMyfirstgameCharacter* character = Cast<AMyfirstgameCharacter>(OtherActor);

	if (character)
	{
		character->ammopool = character->ammopool + count;

		this->Destroy();
	}

}



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

}

Hi,

One thing I noticed is your are attaching your UStaticMeshComponent component to pickuproot when it is still pointing to null. Try to create the pickuproot object first like below, and see if that helps.

Apickup::Apickup()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
      pickuproot = CreateAbstractDefaultSubobject<USceneComponent>(TEXT("pickuproot"));
      RootComponent = pickuproot;

     staticmesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("pickupmesh"));
     staticmesh->AttachToComponent(pickuproot, FAttachmentTransformRules::SnapToTargetIncludingScale);
 
 
      touchsphere = CreateDefaultSubobject<USphereComponent>(TEXT("touchsphere"));
 

 
      
      count = 30;
 
      touchsphere->SetWorldScale3D(FVector(1.f, 1.f, 1.f));
      touchsphere->bGenerateOverlapEvents = true;
      touchsphere->OnComponentBeginOverlap.AddDynamic(this, &Apickup::onpickup);
      touchsphere->AttachToComponent(pickuproot, FAttachmentTransformRules::SnapToTargetIncludingScale);     
 }

Did this help your issue?

All actors automatically have a root component, you just need to create it in the constructor if you want to use their default one. Here is some code which should do attachments correctly:

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

		RootComponent = CreateAbstractDefaultSubobject<USceneComponent>(TEXT("pickuproot"));

		staticmesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("pickupmesh"));
		staticmesh->SetupAttachment(RootComponent);

		touchsphere = CreateDefaultSubobject<USphereComponent>(TEXT("touchsphere"));
		touchsphere->SetupAttachment(RootComponent);
	}