Hello everyone, first post here in the forums. Been learning Unreal on and off for a few months now and trying to tackle more sophisticated systems. I’m a solo developer so reaching out for an issue I’m having hooking up my weapons system.
The basic idea is to create a reusable component to easily standup new weapons in the editor.
Therefore, I have created 3 CPP implementations
- SWeaponData (data Struct)
- SWeaponAsset (of type UPrimaryDataAsset)
- SWeaponComponent (of type UActorComponent)
The Weapon Component is attached to the player actor and references the data from SWeaponAsset (which references the SWeaponData). I would imagine this is a pretty familiar design pattern - the SWeaponComponent will also be references in a Weapon Pickup component later.
The SWeaponComponent will also hold the function for equipping the weapon and have an editor field for the Default Starting Weapon. This is where things are falling apart.
I can create my SWeaonAsset and it’s default properties come over - and holds all the basic weapon properties as well as it’s visual elements (meshs, anims etc). Seen below:
However, when I add the Weapon Component to my BP_Player, I can not input the Data Asset to the Weapon Component. I have messed with editor settings (for example, I allowed the field to accept any BPs derving from DataAsset (thus including UPrimaryDataAsset) and can see the BP and assign there - but I want to be sure that only the UPrimaryDataAsset BPs are listed. Anywho, here’s what my BP_Player with Weapon Component attach looks like:
As you can see these Data Assets exist but are not being populated.
I’m coding all this up on the C++ side but to reduce length here I’ll forego everything but the header file for SWeaponComponent
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "SWeaponAsset.h"
#include "SWeaponComponent.generated.h"
UCLASS(Blueprintable, BlueprintType, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class SPYR_API USWeaponComponent : public UActorComponent
{
GENERATED_BODY()
public:
USWeaponComponent();
// Use fully qualified class path for AllowedClasses
UPROPERTY(EditAnywhere, Category = "Weapon", meta = (AllowedClasses = "USWeaponAsset"))
USWeaponAsset* DefaultWeaponAsset;
UFUNCTION(BlueprintCallable, Category = "Weapon")
void EquipWeapon(USWeaponAsset* NewWeaponAsset);
UFUNCTION(BlueprintCallable, Category = "Weapon")
void UnequipWeapon();
protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
private:
UPROPERTY(Transient)
USWeaponAsset* CurrentWeaponAsset;
UPROPERTY(Transient)
USkeletalMeshComponent* CurrentWeaponMesh;
UPROPERTY(Transient)
ACharacter* OwnerCharacter;
UPROPERTY(Transient)
int32 CurrentAmmo;
public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
Finally, I have also registered these components in the Asset Manager and have pointed them to the correct folder under code.
Any ideas why this drop down isn’t functioning so I can reference the Data Assets? Am I off logically?
Thanks for any help and apologies for the long read but wanted to make sure I gave as much detail as possible! This has been driving me nuts!