Add Box Collision C++ Equivalent?

I’ve been googling and looking around for the C++ equivalent of the Add Box Collision blueprint function and i cant find anything about it.

I’ve been primarily trying out this as an equivalent but it doesnt seem to work like the Add Box Collision:

UBoxComponent* BoxComponent = NewObject<UBoxComponent>(this, UBoxComponent::StaticClass());
BoxComponent->SetRelativeTransform(transform);
BoxComponent->SetBoxExtent(size);
BoxComponent->RegisterComponent();

Nope, dynamically.
NewObject is good for dynamic creation whereas CreateDefaultSubobject is only for the constructor.

Are you doing it in the constructor? You have to do it there.

I have been able to create it dynamically without it being in the constructor fine.
I can literally see it with the “show collisions” command but my method doesnt seem to function like the “Add Box Collision” blueprint function.

oh for…
https://docs.unrealengine.com/latest/INT/BlueprintAPI/AddComponent/Collision/AddBoxCollision/
This function right here!
This is the function that im trying to figure out how to do in C++ but there is quite literally ZERO information about a C++ counterpart for it.

you are not reading the question correctly…
I dont want a C++ to Blueprint function.
I want a Blueprint to C++ function…

trying to convert a blueprint into c++ and it uses that node.
The issue is that with the blueprint one it doesnt list the components attached to the actor but it allows for said components to be hit by trace or multi trace functions.

I would do it with CreateDefaultSubObject in the constructor. If that’s not working then something isn’t right.

The functionality shown does what it’s supposed to do. If you want to do more then you will need to be more specific about what “function like the ‘Add Box Collision’ blueprint function” actually means.
Do you want to add to the functionality of the editor? Or, do you want to have a blueprint-callable function that will add a box collision to an actor/component at runtime?

Just do it yourself. Add a blueprint-callable UFUNCTION to your class and call your box-creation code inside it. And, if you need to, add some code to keep track of the boxes you create – like in an array or something. Exposing Gameplay Elements to Blueprints Visual Scripting in Unreal Engine | Unreal Engine 5.1 Documentation

Well you picked the right Node to look at x) thats a Custom Node “UK2Node_AddComponent” and it calls into AActor::AddComponent

It does not Handle just Box Components it Handles ALL Components.

At this Point you maybe want to describe what you want todo or what is not “working” compared to the existing Node.

I help lots of people and understand them fine. You aren’t explaining yourself clearly. BlueprintCallable lets a blueprint call into C++, and BlueprintImplementable lets C++ call into the blueprint (when implemented). Pick the one you need. But if it’s not calling a C++ function from the blueprint then you’re probably designing it wrong. I assumed you meant expose a C++ function to blueprints because the other way around is kind of dumb unless it’s used to trigger events.

So you simply forgot to Call AttachTo(SomeOtherComponent) then?

Or was it SetupAttachment before you register. One of the two Play around.

not really, the blueprint just calls that function and then exits out, more or less.

This is the blueprint function that i am trying to convert: Add Grid - Box Collision posted by alatnet | blueprintUE | PasteBin For Unreal Engine 4

well, i want to replicate the blueprint in c++ as close as possible. So it might just be my frustration of parts of it not working exactly like the blueprint version.
It does have the correct position. It lists itself within the actor, even though with the blueprint version it doesnt. I might try the last function you have listed to see what i can do.
Beyond that, thank you for helping me with this.

So still don´t get what the Problem is? Do they have the Wrong possition? Don´t get hit? Or you want them to be unlisted inside the Actor or registered with the World instead? Whats the deal here? Pinpoint the Problem.

UBoxComponent* BoxComponent = NewObject<UBoxComponent>(GetWorld());
BoxComponent->SetAbsolute(true, true, true); // Transform is Absolute
 BoxComponent->SetRelativeTransform(transform);
 BoxComponent->SetBoxExtent(size);
// Make sure you setup Collision settings properly etc.
 BoxComponent->RegisterComponentWithWorld(GetWorld());

Here’s my last try. This gives your actor a node that is the same as AddBoxCollision. To the best of my abilities, I think that is what you’re asking. Otherwise, good luck. I did my best to understand.

In your class declaration, add:

UFUNCTION(BlueprintCallable, Category = "MyBoxCollision")
AActor* MyAddBoxCollision(bool ManualAttachment, FTransform RelativeTransform, FName TemplateName);

In your cpp file for the class add:

AActor* MyClass::MyAddBoxCollision(bool ManualAttachment, FTransform RelativeTransform, FName TemplateName)
{
	return NULL; // replace this with the box creation code
}