Page 1 of 1

UE5: How to write converters?

Posted: 29 Jul 2024, 18:11
by ttermeer-reboundcg
I am trying to write converters for UE5 but I am having a hard time finding examples.
So far Noesis is unable to find my class and I have no idea why

here what I wrote so far
#pragma once

#include "CoreMinimal.h"
#include <NsCore/Noesis.h>
#include <NsGui/BaseValueConverter.h>

class StringToUpper final : public Noesis::BaseValueConverter
{
public:
	bool TryConvert(Noesis::BaseComponent* value, const Noesis::Type* targetType,
		Noesis::BaseComponent* parameter, Noesis::Ptr<Noesis::BaseComponent>& result) override;

	NS_DECLARE_REFLECTION(StringToUpper, Noesis::BaseValueConverter)
};
#include "StringToUpper.h"

using namespace Noesis;


////////////////////////////////////////////////////////////////////////////////////////////////////
bool StringToUpper::TryConvert(BaseComponent* value, const Type* targetType,
    BaseComponent* parameter, Noesis::Ptr<BaseComponent>& result)
{
    UE_LOG(LogTemp, Warning, TEXT("StringToUpper::TryConvert"));

    return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
NS_BEGIN_COLD_REGION

NS_IMPLEMENT_REFLECTION_(StringToUpper, "BB2UE5.StringToUpper")
And it is called like this in the XAML:
<UserControl 
...
xmlns:local="clr-namespace:BB2UE5"
...
/>
    <UserControl.Resources>
        <ResourceDictionary>
		<local:StringToUpper x:Key="StringToUpper" />
        </ResourceDictionary>
    </UserControl.Resources>
In the logs it says it unable to find the class:
LogNoesis: Warning: Unknown element type 'local:StringToUpper' (BB2UE5.StringToUpper)
LogNoesis: Warning: StaticResource 'StringToUpper' not found
Any help is appreciated.

Re: UE5: How to write converters?

Posted: 29 Jul 2024, 20:22
by hcpizzi
Hi,

Are you registering your converter? You can see how we do it in our DataBinding sample. We register them in the Game module's StartupModule function and unregister them in the ShutdownModule function.

Please, let us know if that helps.

Re: UE5: How to write converters?

Posted: 30 Jul 2024, 10:39
by ttermeer-reboundcg
Thanks! This is what I was missing. It works now :)