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 custom Actor Component to actors dynamicly

I try to mac a static function looking far all actors with a meshcomponent and to add a custom actor component to them thats what i have that dosent work:

 UWorld* World = WorldContextObject->GetWorld();
     TArray<AActor*> ActorsWithMesh;
     TArray<AActor*> AllActors;
     UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), AllActors);
 
     for (int32 i = 0; i < AllActors.Num(); i++)
     {
         TArray<UStaticMeshComponent*> TempComponents;
         if (AllActors[i])
         {
             AllActors[i]->GetComponents<UStaticMeshComponent>(TempComponents);
             if (TempComponents.Num() > 0)
             {
                 ActorsWithMesh.Add(AllActors[i]);
             }
         }
     }
 
     for (int32 i = 0; i < ActorsWithMesh.Num(); i++)
     {
         UWorldObject* WorldObjectComponent = ActorsWithMesh[i]->CreateAbstractDefaultSubobject<UWorldObject>("WorldObject");
         ActorsWithMesh[i]->AddOwnedComponent(WorldObjectComponent);
     }

How should i do this?

Thanks in advance

kind regards

Sascha

Product Version: Not Selected
Tags:
more ▼

asked Feb 20 '18 at 03:33 PM in C++ Programming

avatar image

SKerkmann
13 1 5 4

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

1 answer: sort voted first

I got it working with

 UWorldObject* WorldObjectComponent = NewObject<UWorldObject>(ActorsWithMesh[i],"WorldObject");
 WorldObjectComponent->RegisterComponent();
more ▼

answered Feb 21 '18 at 07:40 AM

avatar image

SKerkmann
13 1 5 4

(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