Announcement

Collapse
No announcement yet.

Blueprint derived from custom C++ class has incorrect members when loaded

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

    Blueprint derived from custom C++ class has incorrect members when loaded

    Hi Guys,

    I have a custom class, UItem, derived from UObject. It contains a lot of information about a given in-game item, including a reference to an actor blueprint, in case we drop it from an inventory/equip it and want to show the appearance, for example.

    Here's a quick look at the header with all of the extra stuff taken out:

    Code:
    UCLASS(Blueprintable)
    class UItem : public UObject
    {
        GENERATED_UCLASS_BODY()
    
        //The blueprint of the actor
        UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item")
        TSubclassOf<AItemActor> ActorBlueprint;
    }
    AItemActor is derived from AActor.

    In editor, I have created a blueprint derived from UItem - called ShortswordItem. It sets a bunch of variables - including the "ActorBlueprint" variable, which is set to another blueprint, itself derived from AItemActor. Here's how it looks:

    Click image for larger version  Name:	d0038b7915423bb6ddc8209f35099984.png Views:	1 Size:	7.9 KB ID:	1472250
    Clearly labelled "SteelShortswordActor".

    I then load this UItem-derived object in C++. This is how it looks while debugging:

    Click image for larger version  Name:	13ec26b5603fc9b48bad37818ddb5a0b.png Views:	1 Size:	6.6 KB ID:	1472251
    This is correct. However, the ActorBlueprint variable is inexplicably also set to the same value, despite the image before showing it set to the actor:

    Click image for larger version  Name:	546bbee7f3d36e18f7a66d67cc90fe09.png Views:	1 Size:	7.3 KB ID:	1472252

    The ActorBlueprint should be the "SteelShortswordActor" blueprint.

    Have I made a mistake somewhere? Is this a bug? Is there a better approach for this sort of thing?

    Thanks!

    #2
    Hi , have you tried spawning that "ActorBlueprint" class via code in game and see what is spawned to check if it really is a issue of having a wrong class?

    Comment


      #3
      This is not "incorrect".

      "ShortswordItem_C" is instance of the object created by Blueprint's generated class.
      Class was spawned correctly.

      If you spawn it again, next instance will be called "ShortswordItem_C1" and so on...
      | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

      Comment


        #4
        Hey, thanks for the responses.

        Xavier, I'm not sure I follow - ActorBlueprint is a class member that I have assigned type "SteelShortswordActor" to - so why when loaded in C++ is it coming up as ShortswordItem? I appreciate I must be missing something obvious. I fully expect Item to be of that type, but item's ActorBlueprint should surely be the actor i selected? Especially given that it must be a subtype of ItemActor, which ShortswordItem is not

        Comment


          #5
          For further info, im not sure what type to make this pointer. I just want it to represent a type that I later spawn. I've tried TSubclassOf AItemActor, UBlueprint, neither have worked. Any tips would be greatly appreciated

          Comment


            #6
            You have serialized the subclass property.
            When "PostInitProperties" function is called it sets the value back to what it was serialized to.

            If you don't want it serialized then mark it Transient and set the static class yourself.
            ​​​​
            | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

            Comment

            Working...
            X