Download

C++ To Blueprint: Reference Counted object with Blueprint?

I’m working on a game in which I can have multiple zones loaded side by side, determined by a viewport. This viewport ideally should be a shared object (reference counted), but I haven’t found a way to do this with Blueprint.

The ideal situation is that I can have one FWorldMapViewport object registered to multiple worlds, and updating the object will automatically update the referenced object everywhere else. But each world should not be limited to just one viewport (ideally no limit except memory usage and performance).

Is there any way to do this?


// Structure
USTRUCT(BlueprintType)
struct FWorldMapViewport {
	GENERATED_BODY()

	UPROPERTY() int32 x;
	UPROPERTY() int32 y;
	UPROPERTY() int32 z;
	UPROPERTY() int32 size;
};

// Function (inside class AWorldManager)
public:
UFUNCTION(BlueprintCallable, Category = "World Map|Viewport")
		bool RegisterViewport(TSharedRef<FWorldMapViewport> viewport);

In standard C++ this would just be an std::shared_ptr<FWorldMapViewport>, but that doesn’t seem to work with Unreal Engine 4. Neither does taking a TSharedRef as parameter, as Blueprint doesn’t seem to have an idea on how to handle this.

Anyone?
I don’t really know what to do here, cloning and updating manually is an option but this is something I want to avoid. Especially the cloning part.