landongrant
Topic Author
Posts: 4
Joined: 16 Jun 2025, 17:30

Issue driving component bindings with UObject / AActor

05 Nov 2025, 23:00

Hey all,

I've written a custom component that I'd like to reuse which I reference in my main xaml file like this:
<local:MyComponent x:Name="Component1" DataRef="{Binding MyObjects[2]}"/>
Where MyObjects is an array of type that inherits from AActor.

Inside of the component xaml file I have something like this:
<Grid x:Name="MyComponentGrid"
        Width="700" Height="700"
        DataContext="{Binding DataRef, RelativeSource={RelativeSource AncestorType=UserControl}}">
        <Image x:Name="MyComponentImage"
             Source="Images/sourceimg.png"
             Visibility="{Binding bShouldShowImg,
                              Converter={StaticResource BoolToVisibilityConverter}}"/>
        
My intent here is to provide one of the entries in MyObjects as a reference to the DataRef of my component so that I can bind elements like visibility to properties of that object.

It works perfectly fine if I am explicitly setting the DataContext inside of the component to the Ancestor array entry directly like this:
<Grid DataContext="{Binding DataContext.MyObjects[2], RelativeSource={RelativeSource AncestorType=UserControl, AncestorLevel=2}}">

Obviously this isn't scalable so I am wondering why I can't just pass it in like I was above.

Thinking maybe there is something wrong on the C++ side so I tried something like this:
NS_BEGIN_COLD_REGION

NS_IMPLEMENT_REFLECTION(NameSpace::MyComponent, "NameSpace.MyComponent")
{
    auto* dd = NsMeta<DependencyData>(TypeOf<SelfClass>());

    dd->RegisterProperty<AActor*>(
        SeatDataProperty, "DataRef",
        Noesis::PropertyMetadata::Create<AActor*>(nullptr));
}

NS_END_COLD_REGION
But I guess this type of RegisterProperty only works with primitive data types? Maybe I am also misunderstanding...
Appreciate any help that can be given here!
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: Issue driving component bindings with UObject / AActor

06 Nov 2025, 12:07

Hi,

The issue comes from defining the Dependency Property as an AActor*, because that is interpreted as a number by Noesis and we cannot get any reflection information about it.

You should define the property as Ptr<BaseComponent> so we can wrap your Unreal object with one of our types that contains the reflection information about the Unreal type, so bindings can resolve the references to its properties.
NS_IMPLEMENT_REFLECTION(NameSpace::MyComponent, "NameSpace.MyComponent")
{
    auto* dd = NsMeta<DependencyData>(TypeOf<SelfClass>());

    dd->RegisterProperty<Ptr<BaseComponent>>(
        SeatDataProperty, "DataRef",
        Noesis::PropertyMetadata::Create<Ptr<BaseComponent>>(Ptr<BaseComponent>(nullptr)));
}
Could you try that?
 
landongrant
Topic Author
Posts: 4
Joined: 16 Jun 2025, 17:30

Re: Issue driving component bindings with UObject / AActor

06 Nov 2025, 16:59

Absolute legend!

Seems to be working on a very basic case now. I will spend some time to iterate further and will post an update later. Would appreciate if you could also review my implementation once it's ready to ensure I am on the right track.

Thank you for the quick response!

Who is online

Users browsing this forum: No registered users and 4 guests