How to create a UBTTAsk sub task in C++?

I have a melee character with some range, stored in MeleeComponent. I now want to create a task in behaviour tree (using blueprints) that would move to enemy with accepted radius of melee range.
Unfortunately, I cannot set accepted radius for MoveTo (UBTTask_MoveTo) task in the blueprints.

So, instead, I want to create my own task MoveToMelee,in C++, that would create a UBTTask_MoveTo, set the AcceptedRadius with my melee range, and launch it as a subtask: so that when the subtask finishes, it’s result is automatically propagated as a result of my MoveToMelee task. Is this possible?

the UBTNode::NewBTAITask function looks like what I need, but it works with AI tasks, not UBTTasks, and it seems that they can’t be used as UBTTasks.
There ai version of moveTo BTTask - AITask_MoveTo, but I don’t see how to use it as a subtask.

P.S blueprint solutions are also welcome.
P.S. one possible solution to this is to subclass MoveToMelee task from UBTTask_MoveTo directly, but this is ugly.

Seems like you don’t do that. Not with UBTTask at least. They were designed to only be executed internally by the behavior tree framework.

So if in your UBTTask you need to use the functionality of some other UBTTask, the only way would be to subclass from it - but this is very, very bad from design perspective, as this kind of thing needs composition, not inheritance.

But, in the case of MoveTo task - it actually uses AITask, which is more low level task that allowes for composition. It is very clumbersome to use it directly, but luckily our AIController handles that for us.

My solution was to use AIController::MoveTo() and AIController::StopMovement() inside my task.