Announcement

Collapse
No announcement yet.

EditDefaultsOnly - Pointers vs TSubclassOf<>

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    Code:
        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:
    Code:
        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:
    Code:
        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!

    #2
    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.

    Comment


      #3
      Ah okay. Makes sense, thank you

      Comment

      Working...
      X