Add persistent component to placed actor with c++ callineditor

Inherit from UActorComponet (no Transform) or USceneComponent. make sure you add this meta to your UCLASS.

UCLASS(meta=(BlueprintSpawnableComponent))

no, what I want is from C++ create a new component (like doing NewObject(OwnerActor), and then attach it and be able to modify its properties in the level editor, just like a component added to the scene.

You are missing the point of my question, I want to do it but not from the constructor, but from a CallInEditor function, so it creates a button in the editor like this:

and this will replicate the action of doing this:

here you can see the difference of what you propose and what I want:

192085-screenshot_4.jpg

becouse I want the CallInEditor Button to check some things on the level and based on that create multiple staticmeshes accordingly, but I want those staticmeshes to be treated like if they were hand placed components

Well than look into SSCSEditor::PerformComboAddClass I wont dig further than that for you. But thats whats gets executed once you choose a Component from drop Down.

Happy Coding buddy =)

Basically… Is this:

202294-screenshot_1.png

what I want is from C++, in a CallInEditor funciton, create a new component
(like doing NewObject(OwnerActor), and then attach it and be able to modify its properties in the level editor, just like a component added to the scene.

I’ve found that UE creates something called a SimpleConstructionScript, where it caches and restores the items created. but I haven’t got further than that

What I want in the end is to create an utility that takes all the staticmeshes in a box, and destroy the staticmeshactors and spawn the meshes as the components of just one actor. I tried keeping transform and meshes, and building them on construction script, but this won’t allow me to set them as Static. but adding meshcomponentts manually to an actor allows it (and by doing it, it will work with static lighting)

You can add components to a C++ class. Such as:

[.h]

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class MY_API AMyActor : public AActor
{
	GENERATED_UCLASS_BODY()
public:

	AMyActor( );

	UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Mesh")
	class UStaticMeshComponent *MeshComponent;

};

[.cpp]

#include "MyActor.h"
#include "Components/StaticMeshComponent.h"

AMyActor::AMyActor( )
{
	MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh Component"));
	SetRootComponent(MeshComponent);
}

If you then create a Blueprint class from this C++ class, you can then edit “MeshComponent” from the editor.

You’re right, I do not understand. Why not use the Add Component button that already exists?

I mean, the way you add native components is through c++ and not through the details panel of a blueprint class that extends the c++ class. In order to have a native component you need to write the code for it and then compile. This is how native classes handle components.

I suppose you could add a button that adds predefined text to the header file and constructor of a class that the blueprint inherits from and then recompile and that would, if setup correctly, add a native component.