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"

Right method to spawn component at runtime in 2019

Need to add to my "ownedActor" StaticMeshComponent and SkeletalMeshComponent. Tried this

         UStaticMeshComponent *NewComp = ownerActor -> CreateDefaultSubobject <UStaticMeshComponent> (name);
                 
         ownerActor -> AddOwnedComponent (Cast<UActorComponent>(NewComp));

It was compiled, but then crash... What is the right way to add component UE4.21

Product Version: UE 4.21
Tags:
more ▼

asked Jan 22 '19 at 01:35 PM in C++ Programming

avatar image

MasterOfDreams
66 11 11 16

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

1 answer: sort voted first

Hey, there is lot of question about this, but here is a code snippet :)

  USceneComponent* createdComp = NewObject<USceneComponent>(YourComponentsActualClass, this, YourComponentsAddedName);
 2. if(createdComp)
 3. {
 4.     createdComp->RegisterComponent();
 5.     createdComp->AttachTo(GetRootComponent(), NAME_None);
 6. }

where this is the owner of the new component ^^ cheers

more ▼

answered Jan 22 '19 at 02:41 PM

avatar image

AmphDev
1.5k 15 9 34

avatar image MasterOfDreams Jan 22 '19 at 03:20 PM

tried this for UActorComponent and didn't get result for both skinned and static mesh UActorComponent* NewComp = NewObject (UStaticMeshComponent,ownerActor, name); but got it with your method by dividing into too functions, THANKS!

avatar image luis9303 Apr 23 '19 at 07:51 PM

Hi, I have tried that, work fine (creates the components and registers it) but it doesnt ever show that component in the editors panel (in v.4.21.2). Do you know any way to make it visible?

(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