Pass `TAssetPtr` to `BlueprintImplementableEvent`?

I can’t seem to find a way to pass TAssetPtr into a BlueprintImplementableEvent.

Pass-By-Value:

UFUNCTION(BlueprintImplementableEvent)
void OnMyEvent(TAssetPtr<UTexture2D> TextureAssetID);

Fails with this error:

MYPROJ.generated.cpp(156): error C2511: ‘void AMYHUD::OnMyEvent(const TAssetPtr &)’: overloaded member function not found in ‘AMYHUD’

Because MYPROJ.generate.cpp generated void AMYHUD::OnMyEvent(const TAssetPtr& TextureAssetID)

Const-Ref:

UFUNCTION(BlueprintImplementableEvent)
void OnMyEvent(const TAssetPtr<UTexture2D>& TextureAssetID);

Fails with:

MYPROJ.generated.cpp(160): error C2678: binary ‘=’: no operator found which takes a left-hand operand of type ‘const TAssetPtr’ (or there is no acceptable conversion)

Cause generated code tries to write into the parameter.

Pass-by-ref compiles but only let’s the parameter to be used like a out parameter, not an input parameter:

UFUNCTION(BlueprintImplementableEvent)
void OnMyEvent(TAssetPtr<UTexture2D>& TextureAssetID);

I know that Asset IDs should be supported in blueprints since 4.9 and returning an asset id works fine, just passing one is the problem.

Reflection system need to define the function and implement code in to it in order for events work in blueprints when you call function in C++. Insted you need to override with “_Implementation” surrfix in name and i think you need to do BlueprintNativeEvent in order to do so as calling native events from blueprint requires some extra code in reflection system. In base class (with BlueprintNativeEvent) it’s already declered so you need just to define it in cpp file, in child class you need to declere override.

In case of const refrence to fail theres also UPARAM(ref) which inform reflection system that this is suppose to be input refrence pin

 UFUNCTION(BlueprintImplementableEvent)
 void OnMyEvent( UPARAM(ref) TAssetPtr<UTexture2D>& TextureAssetID);

Thanks! Using BlueprintNativeEvent made no difference, but using UPARAM(ref) worked!

Still, is it Unreal’s bug that pass-by-value doesn’t work?

BlueprintNativeEvent still will define function and you can override it, thats why you got OnMyEvent_Implementation generated for that.

Pass-by-value should work i think, you passing by refrence :stuck_out_tongue:

Pass-by-value doesn’t work

UFUNCTION(BlueprintImplementableEvent)
void OnMyEvent(TAssetPtr TextureAssetID);

MYPROJ.generated.cpp(156): error C2511: ‘void AMYHUD::OnMyEvent(const TAssetPtr &)’: overloaded member function not found in ‘AMYHUD’

Ah sry i misread you quastion a little, so i guess it’s limitation or even a bug

It does look like a bug. I’ll leave the question open for a bit, in hopes that someone from Epic can clarify it.

At least UHT should show error before compiler get error that non-refrence TAssetPtr argument is not supported if that the case

Hi grisevg,

Currently Blueprints do not support passing a TAssetPtr by value in this way. The TAssetPtr would need to be passed by reference, either as a const reference or by using the UPARAM macro mentioned by . However, there does seem to be a bug present for passing a TAssetPtr as a const reference that is manifested in the generated code. I have submitted a report to have this investigated further (UE-24034).