Download

Instanced Classes

I am working on getting a generic ability system working in the game. Essentially I have a generic Ability class.



UCLASS(Blueprintable)
class ROGUE_API UAbility : public UObject
{
	GENERATED_UCLASS_BODY()

public :
		
	UFUNCTION(BlueprintNativeEvent, Category = "Abilities")
	void ExecuteAbility(ACharacter* abilityOwner);

	UFUNCTION(BlueprintCallable, Category = "Abilities")
	FName GetAbilityName() const;

private :

	UPROPERTY(EditAnywhere, Category = "Abilities", meta = (AllowPrivateAccess = "true"))
	FName abilityName;

	UPROPERTY(EditAnywhere, Category = "Abilities", meta = (AllowPrivateAccess = "true"))
	UAnimMontage* animationToPlay;
	
};


The character/enemy classes have a UAbility variable which is blueprint editable. The plan is to create different abilities (blueprint classes) with the above class as the base class and then have the designer plug in any ability to any character. The character object would then call the ExecuteAbility and the corresponding animation and gameplay logic will get executed.

The problem i am having is my child ability blueprint classes do not show up in the editor window. Tried using the DefaultClassSpecifier for the UAbility class to check if i get an instanced object for the class but no luck.

Try:


UPROPERTY(EditAnywhere, Category = "Abilities")
TSubclassOf<class UAbility> PrimaryAbilityBP;



// add UPROPERTY header if needed
class UAbility* PrimaryAbility;                           // you'll have to spawn this from the BP class above

Or if you’d rather have a stack of abilities a character can have:


UPROPERTY(EditAnywhere, Category = "Abilities")
TArray< TSubclassOf<class UAbility>> AbilityBPs;



// add UPROPERTY header if needed
TArray< class UAbility*> Abilities;                  // spawn each BP and add to this array

This will let you add BPs in the edtior. It won’t be an instanced object, but the static class you can then spawn the object with in BeginPlay or wherever. I think this is the only practical way to do what you want, I am using a similar system.

You can have UE4 instance the objects for you by tagging the UPROPERTY as “Instanced” and the UAbility UCLASS as “editinlinenew”. It will list all UAbility subclasses and when you pick one you’ll be able to edit it’s properties inline right there.

Thanks guys really appreciate it.

I didnt really want to have 2 variables (class and a instanced ability) for associating an ability with a character but it works fine for what i am doing right now. The instanced property thing is interesting would definitely be a lot more cleaner , will try that out.

Also how would we mark the ability property as instanced if we are adding the variable to a pure BP class. I see some property flags in the editor but nothing about the property being instanced.

You can’t create instanced and EditInline with BP-only classes. At the very least you need a skeleton C++ base class.