not seem to store instances of child classes derived from UCustomClass? It feels like it only accepts objects of the exact base class. I’m assigning these values in a Blueprint, so I would expect it to store instances of UCustomClass and still allow me to cast them to the appropriate child class in C++. However, when I attempt to cast to a child class, the result is nullptr. What could be causing this?
To help you, I think we would need more code context: your custom class definition (and its child), where you assign values in the BP, etc.
I think there is a method to check for the runtime type of an object, maybe you could test that method on the returned object of the Find method to see what’s exactly inside.
I think I forgot mentionning but these are PrimaryDataAsset classes and then I create DataAssets from them:
UCLASS()
class UCustomClass : public UPrimaryDataAsset
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Defaults")
float Damage = 0.f;
};
And here’s the child PDA which is just containing few more variables:
UCLASS()
class UChildClass : public UCustomClass
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
float RandomMultiplier = 0.f;
};
So I am able to create Data Assets from these 2 classes, and then select them in the array, but I can’t access (by casting) to the child at runtime in the array
I’ve done this sort of thing plenty and it’s worked fine. Are you sure you’re looking it up with the same string that you’re adding it to the map?
Have you used your debugger to inspect DataAsset prior to accessing it? Are you sure you’re doing the lookup on an instance of the blueprint that is configured the way that you expect?
There are a lot of unknowns here, but overall the code that you’ve shared should work.
My pleasure. Sometimes it just takes someone asking a “dumb” question that forces you to check things you were otherwise assuming or being slightly blind to. It happens to everyone!