creating instances for editor DataAssets

hi there
i have created a UDataAsset class and created some of them in the editor’s content menu. i have to create instances in the game play (in c++). i am using the code below :


Bag = (UPEBag*)StaticConstructObject(BagContentRef->StaticClass(), BagContentRef);

but it doesnt copy the content of the BagContentRef object.

any idea how to create an instance of a ContentBrowser’s object (in this case a DataAsset object)?

and i can not use “SpawnActor” command because it is not an Actor class

i couldnt find the creating a copy of a dataasset but i found a method called ReinitializeProperties. it works fine :


void APEHrk_Humanoid::BeginPlay()
{
	UPEBag* Bag_ = Bag;
	Bag = new UPEBag(FPostConstructInitializeProperties());
	if (Bag_)
		Bag->ReinitializeProperties(Bag_);
	Super::BeginPlay();
}

The second parameter to StaticConstructObject is the outer, not the template. You almost certainly don’t want to create runtime objects with an outer of an asset (instead either use some related gameplay object as the outer or the transient package via GetTransientPackage()). The template is another parameter to StaticConstructObject, so you can pass it in there and that will save you the call to ReinitializeProperties.


/**
 * Create a new instance of an object.  The returned object will be fully initialized.  If InFlags contains RF_NeedsLoad (indicating that the object still needs to load its object data from disk), components
 * are not instanced (this will instead occur in PostLoad()).  The different between StaticConstructObject and StaticAllocateObject is that StaticConstructObject will also call the class constructor on the object
 * and instance any components.
 * 
 * @param	Class		the class of the object to create
 * @param	InOuter		the object to create this object within (the Outer property for the new object will be set to the value specified here).
 * @param	Name		the name to give the new object. If no value (NAME_None) is specified, the object will be given a unique name in the form of ClassName_#.
 * @param	SetFlags	the ObjectFlags to assign to the new object. some flags can affect the behavior of constructing the object.
 * @param	Template	if specified, the property values from this object will be copied to the new object, and the new object's ObjectArchetype value will be set to this object.
 *						If NULL, the class default object is used instead.
 * @param	bInCopyTransientsFromClassDefaults - if true, copy transient from the class defaults instead of the pass in archetype ptr (often these are the same)
 * @param	InstanceGraph
 *						contains the mappings of instanced objects and components to their templates
 *
 * @return	a pointer to a fully initialized object of the specified class.
 */
COREUOBJECT_API UObject* StaticConstructObject( UClass* Class, UObject* InOuter=(UObject*)GetTransientPackage(), FName Name=NAME_None, EObjectFlags SetFlags=RF_NoFlags, UObject* Template=NULL, bool bCopyTransientsFromClassDefaults=false, struct FObjectInstancingGraph* InstanceGraph=NULL );


Cheers,
Noland

thanks