Projectile mesh not showing in game

Hi everyone,

I am following the projectile tutorial from UE4 as I wanted to try to better understand the best way to implement a basic projectile

However, as I have experience with other parts of UE4 and integrating C++ and Blueprints, I decided to add materials and meshes via the blueprint system directly to the static mesh created as a defaultsubobject in code, rather than using the constructorhelpers (as I do not want to use these later on).

However, when I shoot my projectiles in game, they shoot fine, and when I pause the game I can see them in the world outliner, and eject from my character to focus in on them.

They do not, however, have a mesh or material, so are invisible in game.

Here is the blueprint screen with their mesh component and materials implemented, as well as what they should look like.

I have made sure ‘visible’ is always ticked for all components on this (even the collision component, just for testing), and that hidden in game is also not ticked.

The header code is here.
.h


#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SphereComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"

#include "FPSProjectile.generated.h"

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

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


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

	//Spherical collision component
	UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
		USphereComponent* CollisionComponent;

	//Projectile Movement Component
	UPROPERTY(VisibleAnywhere, Category = Movement)
		UProjectileMovementComponent* ProjectileMovementComponent;

	UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
		UStaticMeshComponent* ProjectileMeshComponent;



	//Function to intiialize projectile velocity in the shoot direction
	void FireInDirection(const FVector& ShootDirection);


	

	
};

The constructor code is here.
cpp:

AFPSProjectile::AFPSProjectile()
{
 	// 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;
	bReplicates = true;

	if (!RootComponent)
	{
		RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("ProjectileSceneComponent"));
	}

	if (!CollisionComponent)
	{
		//Use sphere as simple collision representation
		CollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));

		//Set collision radius
		CollisionComponent->InitSphereRadius(15.0f);

		//Set root component to be collision component as this will be the driven component by the sim
		RootComponent = CollisionComponent;
	}

	if (!ProjectileMovementComponent)
	{
		//Use this component to drive projectile movement
		ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
		ProjectileMovementComponent->SetUpdatedComponent(CollisionComponent);
		ProjectileMovementComponent->InitialSpeed = 3000.0f;
		ProjectileMovementComponent->MaxSpeed = 3000.0f;
		ProjectileMovementComponent->bRotationFollowsVelocity = true;
		ProjectileMovementComponent->bShouldBounce = false;
		ProjectileMovementComponent->Bounciness = 0.3f;
		ProjectileMovementComponent->ProjectileGravityScale = 0.0f;
	}

	if (!ProjectileMeshComponent)
	{
		ProjectileMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProjectileMeshComponent"));

	}

	ProjectileMeshComponent->SetupAttachment(RootComponent);
	
	InitialLifeSpan = 3.0f;
}
...
}

I am very confused about this, so any help would be appreciated. Thank you

Is your spawn actor funtion set to “try to adjust but always spawn”?

Hi 3dRaven,
Thank you for the reply. I have updated my post as I realised I posted the same link twice rather than a link to what the projectile looks like in PIE mode.

I have reduced the size (it was quite large before) of both the collision component and the mesh itself, and also had to disable collisions on the mesh as I had forgotten to do so.

The size is now this (relative to the character who will be firing):
image

I also tried disabling the mesh (clearing it), and could see the collision sphere when placing my bullet blueprint in the world, but when firing I still cannot see any object (even when ejecting and selecting it in the paused game). The result has always been the same as the image I have now put on the post.

Thank you for the help so far

Sorry edited my last post by accident (on mobile) that’s what i wanted to send

Thanks for the help. It was an issue with the spawn actor function, but it was because I was trying to create from the base projectile C++ class (which always has an empty mesh) rather than from the desired blueprint which I was setting (with the mesh and collision set properly). It all works now.

1 Like