How to make a clone or copy of a UObject in a blueprint

There must be some way of doing this, surely, without defining a method like in the screenshot. Just take the object, make a copy, give me the copy.

Note I specifically do not want a reference (pointer) to the original object. I want a completely separate, identical copy of the object, such that if I change object B, object A’s properties are not affected in any way whatsoever.

Completely separate. I must have missed something here? It’s so fundamental to be able to clone or copy an object, there must be some kind of way to do this in blueprints?!

You ever figure this out?

There is no way without cpp unfortunatly.
But if you know how to add cpp to your project here is the code that will generate this node.
image

.h


.cpp

.h
#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "UObject/UObjectGlobals.h"
#include "MyGameBPFunctionLibrary.generated.h"

UCLASS()
class MYGAME_API UMyGameBPFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

	UFUNCTION(BlueprintCallable, meta = (DeterminesOutputType = "SourceObject", DefaultToSelf="Outer"),Category="MyGame Utilities")
	static UObject* DuplicateObject(UObject const* SourceObject,UObject* Outer);
	
};
.cpp
#include "MyGameBPFunctionLibrary.h"

UObject* UMyGameBPFunctionLibrary::DuplicateObject(UObject const* SourceObject,UObject* Outer)
{
	if(IsValid(SourceObject) && IsValid(Outer))
	{
		const FName DuplicatedObjectName = MakeUniqueObjectName(Outer,SourceObject->StaticClass());
		return StaticDuplicateObject(SourceObject,Outer,DuplicatedObjectName);
	}
	else
	{
		return nullptr;
	}
}
3 Likes