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!