Hopefully, this question will be easier to answer than some of my previous questions…
In this project, I have set-up a class for a projectiles in game (QTBDWeaponProjectile), this is as shown below:
Header:
#pragma once
#include "QTBDItem.h"
#include "QTBDWeaponProjectile.generated.h"
/**
* For all projectiles in Quest: To Be Defined.
*/
UCLASS()
class QUESTTOBEDEFINED_API AQTBDWeaponProjectile : public AQTBDItem
{
GENERATED_BODY()
public:
// Properties:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Movement)
class UProjectileMovementComponent* WeaponProjectileMovementComponent;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = ProjectileProperties)
FVector DefaultProjectileScale;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = ProjectileProperties)
float ProjectileLifespan;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = ProjectileProperties)
float InitialProjectileSpeed = 6000.f;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = ProjectileProperties)
float MaximumProjectileSpeed = 6000.f;
// Methods:
/** The default constructor for QTBDWeaponProjectiles. */
AQTBDWeaponProjectile();
virtual void BeginPlay()override;
};
Implementation:
#include "QTBDWeaponProjectile.h"
#include "QuestToBeDefined.h"
#include "Runtime/Engine/Classes/GameFramework/ProjectileMovementComponent.h"
#include "Runtime/Engine/Classes/Components/StaticMeshComponent.h"
#include "Runtime/Engine/Classes/Components/CapsuleComponent.h"
/** The default constructor */
AQTBDWeaponProjectile::AQTBDWeaponProjectile()
{
// There were more lines here for initialisation of other components,
// as well as setting-up WeaponProjectileMovementComponent to what I thought
// made sense, this has been removed to keep it as similar to the Blueprint
// implementation:
WeaponProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(FName("WeaponProjectileMovementComponent"));
}
void AQTBDWeaponProjectile::BeginPlay()
{
// So that projectiles are removed after a time:
SetLifeSpan(ProjectileLifespan);
}
For reference, are the header and implementation files for QTBDItem, respectively:
#pragma once
#include "QuestToBeDefined.h"
#include "GameFramework/Actor.h"
#include "QTBDEntity.h"
#include "QTBDItem.generated.h"
/**
* For all items in Quest: To Be Defined (such as projectiles, weapons, armour etc.).
*/
UCLASS()
class QUESTTOBEDEFINED_API AQTBDItem : public AActor
{
GENERATED_BODY()
public:
/** This flag will state whether the player is overlaping the ProximitySphere, the player can then pick up this item */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Flags)
bool bIsPlayerOverlapingPickupSphere;
/** The name of this particular item */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = ItemFields)
FString ItemName;
/** The mass of this particular item, in kilograms */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = ItemFields)
float ItemMass;
/** The cost to purchase this item, if being sold instead, it can be sold for 75% of this value */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = ItemFields)
float ItemValue;
/** This flag relates to whether this item has been picked up or not */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Flags)
bool bHasBeenPickedUp;
/** Event for blueprint to use, to carry out actions, when the item has been picked up */
UFUNCTION(BlueprintNativeEvent, meta = (DisplayName= "On Item Pick up"), Category = Pickup)
void OnItemPickup();
/** Use this whenever this item is in the player's inventory */
UFUNCTION(BlueprintCallable, meta = (DisplayName= "Has now been picked up"), Category = PickupValidation)
void NowInPlayerInventory();
/** Set the 'IsPlayerOverlapingPickupSphere' var. to true */
UFUNCTION(BlueprintCallable, meta = (DisplayName= "Player is overlaping the pickup sphere"), Category = PickupValidation)
void PlayerOverlapingPickupSphere();
/** Set the 'IsPlayerOverlapingPickupSphere' var. to false */
UFUNCTION(BlueprintCallable, meta = (DisplayName= "Player is not overlaping the pickup sphere"), Category = PickupValidation)
void PlayerNotOverlapingPickupSphere();
/** The standard constructor. */
AQTBDItem();
};
#include "QTBDItem.h"
#include "QuestToBeDefined.h"
AQTBDItem::AQTBDItem()
{
// The player will not be overlaping this item, upon the iteme spawning into the level
bIsPlayerOverlapingPickupSphere = false;
// The player can't have picked up this item yet either
bHasBeenPickedUp = false;
}
void AQTBDItem::PlayerOverlapingPickupSphere()
{
bIsPlayerOverlapingPickupSphere = true;
}
void AQTBDItem::PlayerNotOverlapingPickupSphere()
{
bIsPlayerOverlapingPickupSphere = false;
}
// Implementation is provided in Blueprint for these functions:
void AQTBDItem::OnItemPickup_Implementation()
{
}
// Called whenever the item has been picked up, also fires off an event that blueprint can use:
void AQTBDItem::NowInPlayerInventory()
{
bHasBeenPickedUp = true;
// Call this event for blueprint to handle:
OnItemPickup();
}
I have then created a Blueprint Class, that inherits from QTBDWeaponProjectile, leaving the values for WeaponProjectileMovementComponent at the default. Other components to visual this projectile and handle collision are added via Blueprint. Having this actor spawned into the world though, then having the engine simulate the level, shows the projectile as remaining stationary.
When I set-up a Blueprint that inherits from the Actor class though (adding components to it via Blueprint), as shown below…
…with the values for the ProjectileMovementComponent left at their defaults, allows for a projectile that, when spawned into the game world, moves as per the ProjectileMovementComponent (this is what is expected).
Please feel free to ask me any questions in relation to any details that I have missed.
I am not sure why this is, it would seem as though I am missing something. Could someone let me know what the issue is? Thanks in advance.