Download

EditDefaultsOnly - Pointers vs TSubclassOf<>

Hi,

I’ve just started learning Unreal and I’m trying to expose a variable from one of my classes to be set in the editor.

For example this code works fine:


    UPROPERTY(EditDefaultsOnly, Category="Particles")
    UParticleSystem* ParticleSystem;

I can then assign any particle effect I want. However if I want to do the same thing for a custom class I have made, it no longer works:


    UPROPERTY(EditDefaultsOnly, Category="Weapon")
    APXBaseWeapon* MyWeapon;

I can see the field under Class Defaults in the editor, but I can not select any of my APXBaseWeapon subclasses, or even the base class itself (including blueprint extensions of these). The only way I can get it to work is to do:


    UPROPERTY(EditDefaultsOnly, Category="Weapon")
    TSubclassOf<APXBaseWeapon> MyWeapon;

Why are they different? I’m confused why I have to use two separate methods when I feel like I’m essentially doing the same thing.

Thanks!

When you create a Particle System in the content browser you are creating a new ‘UParticleSystem’ object directly, hence you can set the pointer to that asset.

When you create a Blueprint, you are (sort of, it gets complicated) creating a Class. The Blueprint is a Class of APXBaseWeapon, not an APXBaseWeapon.

Ah okay. Makes sense, thank you :slight_smile: