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"

Procedurally set EditAnywhere (UPROPERTY)

> please also see related forum post

How do I set a dynamically spawned Component/Actor to EditAnywhere if I cannot use the UPROPERTY() macro, since this is purely runtime based from c++.

I want to spawn a child actor via UChildActorComponent, which works to some extent. But the spawned child actor is not editable or selectable in the World Outliner or Editor Viewport. But setting a UPROPERTY() macro is not possible since the actor and UChildActorComponents are spawned at runtime and I do not have class attribute where I could put the UPROPERTY() macro. So I need to be able to set an Actor/Component to EditAnywhere purely from C++ at runtime. How do I do this=

 UChildActorComponent* NewComp1 = NewObject<UChildActorComponent>(this);
 NewComp1->bEditableWhenInherited = true;
 NewComp1->RegisterComponent();
 NewComp1->SetChildActorClass(AMyChildActor::StaticClass());
 NewComp1->CreateChildActor();

Related, but not answered / working: "> How to add UPROPERTY dynamically?"

Product Version: UE 4.20
Tags:
more ▼

asked Jul 29 '18 at 08:22 PM in C++ Programming

avatar image

chrarlait
26 1 3 7

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

1 answer: sort voted first

It's not practical because you will need to add property to UClass and this will alter class information and all objects on the level of that class, possibly permanently since UClass don't reset with the world.... and i don't see reason why you would want to have it in first place, there easier way to do this:

Just make

 UPROPERTY(EditInstanceOnly, Instanced)
 AMyChildActor* ChildActor;

EditInstanceOnly will make it visible only in level property editor and Instanced will make actor properties editable. And then after NewComp1->CreateChildActor(); do this:

 ChildActor = NewComp1->GetChildActor();


more ▼

answered Jul 30 '18 at 12:21 AM

avatar image

Shadowriver
37.3k 936 172 1117

(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