x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Add persistent component to placed actor with c++ callineditor

Basically... Is this:

alt text

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)

Product Version: UE 4.16
Tags:
screenshot_1.png (42.0 kB)
more ▼

asked Jul 13 '17 at 08:04 PM in C++ Programming

avatar image

0xAFBF
36 2 5 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

 UCLASS(meta=(BlueprintSpawnableComponent))
more ▼

answered Jul 13 '17 at 08:44 PM

avatar image

Nachtmahr
7k 143 28 172

avatar image 0xAFBF Jul 14 '17 at 02:41 AM

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.

avatar image Vawx Jul 14 '17 at 02:47 AM

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.

avatar image 0xAFBF Jul 14 '17 at 02:58 AM

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:

alt text

and this will replicate the action of doing this:

alt text

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

alt text

screenshot_3.jpg (75.1 kB)
screenshot_2.jpg (95.1 kB)
screenshot_4.jpg (68.5 kB)
avatar image Vawx Jul 14 '17 at 03:11 AM

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.

avatar image 0xAFBF Jul 14 '17 at 03:15 AM

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

avatar image Nachtmahr Jul 14 '17 at 03:52 AM

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 =)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question