Reference Object Autocast Blueprint

Hello, I made an autocast blueprint convert function for UObject.

UFUNCTION(BlueprintPure, meta = (DisplayName = "Object To UniversalParameter", CompactNodeTitle = "->", BlueprintAutocast), Category = "")
	static FUniversalParameter Conv_ObjectToUniversalParameter(UObject* obj);

It woks well basically but the node not automatically link the object reference node into them (like self node)

If I need to declare a separate autocast function for object references, I’m willing to do so. How do I do that?

Manually link available

You can create another autocast function specifically for object references by declaring it as follows:

UFUNCTION(BlueprintPure, meta = (DisplayName = "Object Reference To UniversalParameter", CompactNodeTitle = "->", BlueprintAutocast), Category = "")
	static FUniversalParameter Conv_ObjectRefToUniversalParameter(TWeakObjectPtr<UObject> objRef);

Here, the function takes in a TWeakObjectPtr which is a type of object reference that can handle the case where the referenced object is destroyed. This way, if you pass in a self reference or any other object reference node, the function will handle it correctly.

Note that you will need to implement the body of the function and define the FUniversalParameter structure to convert the object reference to the desired data type.

I didn’t try the code above, so let me know if you run into any issues.

First of all, thanks for your reply. I tried the fix you suggested and the bottom line is that it failed to compile.

UHT says

Type ‘TWeakObjectPtr’ is not supported by blueprint. Conv_ObjectRefToUniversalParameter.objRef

I assume that I can’t use that WeakObjectPtr type for passing into Blueprint, so I’ll stick to converting manually for now.