Unreal converter C++ help

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!