I want to be able to make a modular weapon with various components to handle each specific aspect. I have found EditInlineNew / Instanced to be exactly what I need - Except for one main problem.
I define a BaseWeaponBallistics class and created two classes deriving from it:
UCLASS(Abstract, EditInlineNew, Blueprintable) class UBaseWeaponBallistics : public UActorComponent UCLASS(Blueprintable) class UWeaponBallisticsProjectile : public UBaseWeaponBallistics UCLASS(Blueprintable) class UWeaponBallisticsHitscan : public UBaseWeaponBallistics
In my BaseWeapon class, I then add this as a property:
/** Weapon Ballistics */ UPROPERTY(EditAnywhere, Instanced, Category = "Weapon") class UBaseWeaponBallistics* Ballistics;
Now, I can choose my subclass and set the various properties in the editor. Here, I am editing a Blueprint deriving from BaseWeapon:
I can save this Blueprint, compile it, and everything works as expected when I Play In Editor. My weapon fires off the projectile or hitscan as expected. However when I close the editor and re-open it, my choice has been set to default:
How can I fix this?
Edit: It appears to be specific to UActorComponent. When I made the following change, the value persists across reloading the editor:
class UBaseWeaponBallistics : public UObject
Worth noting that it saves fine when derived from UActorComponent; ie changing it to UObject and then reloading the editor shows the selection that I had previously made. It seems to me that the problem is somehow in loading the component.
This can suffice for now, I can get by with manually setting the AActor owner for the component. However, I would like to know if this is expected behavior or not. Am I missing something, or should I report this as a bug?