Unreal converter C++ help

Hey guys,

I’m not sure where to post this and if this is not appropriate please help me move this (there is also no C++ tag).
I havent been in C++ for awhile and also unfamiliar with unreal in general and looking the code has left me stuck at some place I am not sure how to find out about.
Basically I’ve traced the SpeckleConverters in the speckle-unreal connector to the
UObject* UAggregateConverter::ConvertToNativeInternal(const UBase* Object, UWorld* World) function (AggregateConverter.cpp, Line 49), in which it returns Execute_ConvertToNative(Converter, Object, World, MainConverter)

I am not sure where this leads as it seems to refer to the SpeckleConverter.generated files. Visual Studio also stops at ISpeckleConverter’s GENERATED_BODY() line.

My question is if there is a way for me to understand how you are achieving this, and a way for me to trace past this point, because I do not see the actual declaration for the function anywhere? is there a function type that prepends “Execute_” and its recognised by Unreal? I’m quite lost as to where to start looking, and a few pointers in the right direction would be very much welcome.

I was actually looking to see if i could add some stuff if i could get familiar enough with the code base.
At this instance possibly just a quick-fix to add simple collision box to the environment to be able to interact with (mostly the floor and walls) the model. A hint on the general area where this could be achieved would be appreciated as well.
And since I’m here i was wondering if that’s on the roadmap anywhere for the unreal connector.

I hope this is okay and thanks for always being a great help.

1 Like

Hi @eugeneida

Looks like you’ve really taken a deep dive into the Unreal connector, impressive :raised_hands:

Hopefully I can help illuminatesome things (although, this level of depth isn’t strictly necessary to understand if your goal is to write some custom conversion logic, see last few paragraphs)

You’re suspicion was mostly correct. The GENERATE_BODY() macro is used by the UHT source generator, and is required by all classes marked with UClass or USTRUCT.
This macro populates the .generated file with the required constructors and blueprint thunks (yes they are called thunks) to allow a class to work with Unreal’s serialization/reflection and garbage collection system, which are the foundation to how UObjects operate. The .generate files are quite scary, and not really fit for human consumption so I’d recommend not looking at them directly for too long :grin:.

In the case of interfaces like ISpeckleConverter, Unreal does a lot of magic behind the scene to allow them to used and implemented by Blueprint.

So the ISpeckleConverter interface defines a ConvertToNative function.
C++ implementers will implement a ConvertToNative_Implementation function.
And callers will call the Execute_ConvertToNative function.

Not intuitive I know! But this is the Unreal way, and is what facilitates the interop between Unreals blueprint system.
The Unreal docs provide a more complete explanation if you’re curious.


On the topic of using Speckle Unreal,
I recommend you first checkout this tutorial Unreal - Developing Custom Object Conversions that walks you through how you can create your own custom converter.

In your case, you could create a custom mesh converter that first calls the existing and then attaches a collider component.
You can do this in either C++ or Blueprint, either way, you’ll be creating a UObject class/bp that implements ISpeckleConverter and implements CanConvertToNative and ConvertToNative.
Likely, you’ll want to declare a UPROPERTY to pass in the existing mesh converter so that can be called from your function. Then you write your own logic to attach any custom Components you desire.

We did something pretty similar here Grasshopper to Unreal - asset swap / mapping meshes from Grasshopper proof of concept in Blueprint to swap some meshes with native ones.

You may instead prefer to extend/inherit the existing StaticMeshConverter to override the functions you need. This can only be done in C++.

A lot of this can be quite daunting if you’re new to either C++, Unreal, or Speckle. So please don’t hesitate to ask any questions.
And let me know how you get on (since what you’re describing sounds super cool :grin:, id love to hear about your progress)


And as a side note; Generally it’s preferred that you write your own classes rather than modify the existing classes. To avoid any conflicting changes when you come to update your connector with a newer version. Unless of course you’re just experimenting, or looking to contribute back to the Unreal connector, then fork away!

Hi Jedd,

Thanks for the prompt reply as always. There a few things coming up immediately for me (outside of speckle) so i’ll reply first.

So the ISpeckleConverter interface defines a ConvertToNative function.
C++ implementers will implement a ConvertToNative_Implementation function.
And callers will call the Execute_ConvertToNative function.
This was the suspicion and I’m glad for your confirmation. So there is some Unreal magic to put these together and link them as long as they follow this pattern.

I’ll definitely look up the interface doc, it is what i needed. Thanks alot!

On the topic of using Speckle Unreal,
I recommend you first checkout this tutorial Unreal - Developing Custom Object Conversions that walks you through how you can create your own custom converter

I didnt see this back then when I was looking it up, but a cursory glance seems to be what i was wanting to know about Speckle. Also very helpful, again thanks!

And as a side note; Generally it’s preferred that you write your own classes rather than modify the existing classes. To avoid any conflicting changes when you come to update your connector with a newer version. Unless of course you’re just experimenting, or looking to contribute back to the Unreal connector, then fork away!

Oh I plan to give you lots of trouble! :slight_smile: Well to be honest, we are still quite early in development and we definitely haven’t ruled out contributing back to the connector, but absolutely nothing is concrete and we’ll see how we progress.

It might be awhile before I post again maybe in this same thread, but I hope to do so as soon as I can!