Problem with DuplicateObject() and XmlParser

Hello everyone, I’m currently trying to expose some of UE4’s XmlParser code to blueprints, but I’m running into some problems. I think my problem is with DuplicateObject() not duplicating the object correctly? I am unsure if FXmlFile will duplicate with that function or not, but when I test it, it crashes. Here’s my code.


UCLASS(BlueprintType)
class EASYXML_API UEasyXMLObject : public UObject
{
	GENERATED_BODY()
	
public:
	UEasyXMLObject();
	~UEasyXMLObject();

	void InitObject(FString XMLString);


// Blueprint functions
public:
	UFUNCTION(BlueprintCallable, Category = "EasyXML")
		UEasyXMLObject* GetFirstChildNode();

//private:
	FXmlFile EasyXMLFile;
	const FXmlNode* CurrentNode;
};

void UEasyXMLObject::InitObject(FString XMLString)
{
	// Load the XML file into EasyXMLFile
	EasyXMLFile.LoadFile(XMLString, EConstructMethod::Type::ConstructFromBuffer);

	CurrentNode = EasyXMLFile.GetRootNode();
}

UEasyXMLObject* UEasyXMLObject::GetFirstChildNode()
{
	UEasyXMLObject* temp = DuplicateObject<UEasyXMLObject>(this, NULL);
	temp->CurrentNode = temp->CurrentNode->GetFirstChildNode(); // crashes with this line, I believe
	return temp;
}

I have tried using pointers as well, so instead of just FXmlFile, i used FXmlFile* and deleting the memory manually in BeginDestroy() or the destructor, but I had zero luck! I’m bashing my head against my keyboard trying to figure this out. Does anyone have any suggestions? Thank you so much for the help!

I’ve narrowed it down but still cant figure it out…

Problematic code:


temp->CurrentNode = temp->CurrentNode->GetFirstChildNode();

Current Node is of type const FXmlNode* and **GetFirstChildNode() *also returns a const FXmlNode, so I’m not sure why this isn’t working. Does anyone have any insight as to why this is causing a crash? Am I doing something stupidly obvious?

Hi metiri,

is temp->CurrentNode null perhaps?
I didn’t run it, but this looks to me as if currentNode isn’t set yet.
I’d try to set temp.CurrentNode = temp.GetRoot (or something like that, dont have source at hand), then you can get other child nodes.