How to access a dynamic asset pointer?

I want to let the designer choose a SkeletalMesh asset on the Editor directly in my C++ AActor instance (not in Blueprints defaults by extending the class) through the asset picker. I’m gonna use it in C++ to create SkeletalMeshComponents but, in every way I’ve tryed, I ended up with a nullptr.

Tryed

UPROPERTY(EditAnywhere)
USkeletalMesh* SkeletalMesh; // shows asset picker in Editor but in code is always nullptr

 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 UPROPERTY(EditAnywhere)
TAssetPtr<USkeletalMesh> SkeletalMesh; // calling IsNull and IsValid returns true and false, consecutively

I saw this tutorial but it’s async loading and I didn’t test it. Ain’t there a way to get access to an asset pointer synchronously? This page shows the SoundCue example just like my first method above, but using EditDefaultsOnly. That way I’m forced to extend the class in BP and I don’t want that. I’d just like to throw my C++ class in the World and use it directly. Then, the page also shows the Indirect Property Reference method, using TAssetPtr with the methods LoadObject<>() and StaticLoadObject(). But I couldn’t find how to use them. And they too seem to be usable with EditDefaultsOnly.

Please, what am I missing here? Isn’t it possible to do what I want? (use asset pointer directly in C++ AActor instance).

Nobody? I’m starting to believe there’s no way to do it.

UPROPERTY(EditAnywhere)
USkeletalMesh* mySkeletalMesh;

 UPROPERTY(EditInstanceOnly)
 USkeletalMesh* mySkeletalMesh;

It’s pretty basic really, so no problem there : it is doable. The reason no one may have answered is that you are probably missing something else that is not explained in your post. There is no need for async loading or whatever.

If in the editor you set a value to mySkeletalMesh it will be set and in begin play you can assign it to your skeletal mesh component. Or on OnConstruction, which would be better so you can see it in the editor.

Alternatively, the SkinnedMeshComponent (parent to SkeletalMeshComponent) already has that variable:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Mesh")
	class USkeletalMesh* SkeletalMesh;

So, you dont really need to do it in your custom class, the designer can very easily just select the skeletal mesh component from your actor and set the SkeletalMesh asset there.

Let me know if I can be of further help!

Mick

OnConstruction should be called everytime you change a property. It does on my project at least :slight_smile:

I don’t understand. I tried it in another project (one I use for tests, only) and it worked. As simple as I thought it should be. I put the SkeletalMesh to be applied to the SkeletalMeshComponent on PostEditChangeProperty and it just worked. I have no idea why it didn’t before, on the other project. I tried the same code!! At least, I believe I did. I’ll try it again sometime.

Thanks for the answer! I didn’t know about the OnConstruction. Interesting thing, though: I thought it worked like BP (everytime you change something, it “constructs” again). But it’s called only upon Spawn/Instantiation. I had to use PostEditChangeProperty to see the skeletalMesh change as I picked different ones from my proj content folders.

The best thing about it working is that Unreal C++ is not as hard to use as I was fearing it would be.

That’s odd… The documentation says it’s only on Spawn/Instantiation as it happens for me. I wonder why does it gets called on property change for you. What engine version are you using?

I’m very confused now… I tested again with only the OnConstruction function and it behaved as you said. Thats good, at least. Less required events to write. Thanks for everything!