Hello!
I’m trying to use a blueprint class as a property but I see no items in the list.
I have a blueprint of BaseMeleeWeapon but can’t use it as a property in WeaponComponent of my BaseCharacter.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon")
ABaseMeleeWeapon* MeleeWeapon;
It doesn’t appear in the list unless I drag it to the scene but it doesn’t allow me to assign it anyway.
3dRaven
(3dRaven)
June 25, 2023, 9:09pm
2
You can’t set a blueprint instance from within the blueprint, only from within a level (it needs the instance of that object to exist, because it is a pointer).
You can on the other hand use
UPROPERTY(EditAnywhere,BlueprintReadWrite)
TSubclassOf<ABaseMeleeWeapon> MeleeWeapon;
This will be a UClass of the object, with the filter of ABaseMeleeWeapon
so it will encompass any class that also derives from it.
You can then use the class to spawn an actor from it.
Otherwise you need to populate it with an instance that is already in the world with for instance get actor of class or direct in level setting.
1 Like
This is right, but I highly recommend using the following for memory optimization:
TSoftClassPtr<ABaseMeleeWeapon>
It works the same as TSubclassOf, but it lets you manage when to load it into memory.
All about Soft and Weak pointers | Tutorial
2 Likes
3dRaven
(3dRaven)
June 25, 2023, 9:21pm
4
@Fus_Ro_Duh Don’t forget to load it later on though
UPROPERTY(EditAnywhere,BlueprintReadWrite)
TSoftClassPtr<ABaseMeleeWeapon> MeleeWeapon;
Before you use it you need to load it
MeleeWeapon.LoadSynchronous();
2 Likes
system
(system)
Closed
July 25, 2023, 9:21pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.