Loading XAML Interfaces and Textures in Unreal Engine 5 without Importing
Hi NoesisGUI Community,
I need some help with loading XAML interfaces and textures in Unreal Engine 5 without importing them directly into the project. I've tried loading the XAML file and casting my parsed result to UNoesisXaml in the constructor of my class that extends public UNoesisInstance, but the interface remains black.
Here is my test code:
Despite the code, my interface stays black. Can anyone provide guidance on the correct approach to load XAML interfaces and textures dynamically in UE5?
Thank you in advance!
Best regards,
P.Claudon
I need some help with loading XAML interfaces and textures in Unreal Engine 5 without importing them directly into the project. I've tried loading the XAML file and casting my parsed result to UNoesisXaml in the constructor of my class that extends public UNoesisInstance, but the interface remains black.
Here is my test code:
Code: Select all
FString XamlFilePath = FPaths::ProjectContentDir() + TEXT("../Assets/ConnectingGUI/MainWindow.xaml");
FString XamlContent;
if (FPaths::FileExists(XamlFilePath))
{
FFileHelper::LoadFileToString(XamlContent, *XamlFilePath);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Xaml not Found : %s"), *XamlFilePath);
}
UNoesisXaml* MyXaml = NewObject<UNoesisXaml>();
if (!XamlContent.IsEmpty())
{
std::string XamlText = TCHAR_TO_UTF8(*XamlContent);
Noesis::Ptr<Noesis::BaseComponent> XamlRoot =
Noesis::GUI::ParseXaml(XamlText.c_str());
BaseXaml = reinterpret_cast<UNoesisXaml*>(XamlRoot.GetPtr());
}
else
{
UE_LOG(LogTemp, Error, TEXT("Error when loading XAML"));
}
Thank you in advance!
Best regards,
P.Claudon
Re: Loading XAML Interfaces and Textures in Unreal Engine 5 without Importing
Hi,
The way to do it, once you've loaded the XAML text, is to create an UNoesisXaml and set its XamlText property.
However, take into account that if the XAML depends on other XAML files (say, it includes a ResourceDictionary), or images or any othe external resource, these dependencies won't be found.
The way to do it, once you've loaded the XAML text, is to create an UNoesisXaml and set its XamlText property.
Code: Select all
UNoesisXaml* NoesisXaml = NewObject<UNoesisXaml>();
NoesisXaml->XamlText.Insert((uint8*)XamlText.c_str(), XamlText.length(), 0);
Re: Loading XAML Interfaces and Textures in Unreal Engine 5 without Importing
I tried following the advice but I'm encountering an issue. I'm receiving the warning: LogNoesis Xaml not found ''.
Here is the code I'm using:
Any guidance or suggestions on what might be causing this issue would be greatly appreciated.
Thank you in advance!
Here is the code I'm using:
Code: Select all
// TestNoesis.cpp
#include "TestNoesis.h"
#include "DataContext.h"
#include "NoesisRuntime.h"
#include "NoesisXaml.h"
UTestNoesis::UTestNoesis(const FObjectInitializer& ObjectInitializer)
{
DataContext = ObjectInitializer.CreateDefaultSubobject<UDataContext>(this, TEXT("DataContext"));
FString XamlFilePath = FPaths::ProjectContentDir() + TEXT("../Assets/ConnectingGUI/MainWindow.xaml");
FString XamlContent;
if (FPaths::FileExists(XamlFilePath))
{
FFileHelper::LoadFileToString(XamlContent, *XamlFilePath);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Xaml not Found : %s"), *XamlFilePath);
return;
}
if (!XamlContent.isEmpty())
{
std::string XamlText = TCHAR_TO_UTF8(*XamlContent);
UNoesisXaml* NoesisXaml = NewObject<UNoesisXaml>();
NoesisXaml->XamlText.Insert((uint8*)XamlText.c_str(), XamlText.length(), 0);
// UE_LOG(LogTemp, Warning, TEXT("%s"), *XamlContent); // Content is correctly read
BaseXaml = NoesisXaml;
// BaseXaml->XamlText.Insert((uint8*)XamlText.c_str(), XamlText.length(), 0); // I've tried this way but it results in the same error
}
else
{
UE_LOG(LogTemp, Error, TEXT("Error when loading XAML"));
}
}
void UTestNoesis::NativeConstruct()
{
Super::NativeConstruct();
DataContext->BaseXaml = BaseXaml;
SetDataContext(Cast<UObject>(DataContext.Get()));
}
// TestNoesis.h
#pragma once
#include "CoreMinimal.h"
#include "NoesisInstance.h"
#include "DataContext.h"
#include "TestNoesis.generated.h"
UCLASS()
class UTestNoesis : public UNoesisInstance
{
GENERATED_BODY()
public:
UTestNoesis(const FObjectInitializer& ObjectInitializer);
virtual void NativeConstruct() override;
private:
UPROPERTY()
TObjectPtr<class UDataContext> DataContext;
};
// DataContext.h
#pragma once
#include "CoreMinimal.h"
#include "NoesisXaml.h"
#include "UObject/Object.h"
#include "DataContext.generated.h"
UCLASS()
class SNPROJECTCLIENT_API UDataContext : public UObject
{
GENERATED_BODY()
public:
UDataContext();
UNoesisXaml* BaseXaml;
};Thank you in advance!
Re: Loading XAML Interfaces and Textures in Unreal Engine 5 without Importing
Hello,
I managed to solve the problem by using the following code:
This allowed me to successfully load the XAML interfaces and textures in Unreal Engine 5 without having to import them directly into the project. I hope this can help others who are facing the same issue.
I managed to solve the problem by using the following code:
Code: Select all
const char* xamlText = reinterpret_cast<const char*>(XamlText.GetData());
return Noesis::GUI::ParseXaml(xamlText);
Re: Loading XAML Interfaces and Textures in Unreal Engine 5 without Importing
Thanks for letting us know! Closing this.
Who is online
Users browsing this forum: No registered users and 17 guests