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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Component added dynamically disappears in PIE

I'm trying to create a custom component based on this tutorial video in order to facilitate level design. I basically want to be able to add it to a class and have it clone all scene components that are children of the root, offsetting them until an endpoint is hit.

To go from this: alt text

to this: alt text

and duplicate any meshes, shapes, etc.

It seems to work well enough in the Blueprint Component window, but when I place it in the scene and play in editor, all the added components disappear.

Stopped: alt text

Playing: alt text

This seems to clear up when I save the blueprint, or sometimes for seemingly no reason, and comes back when I change any properties of the wall.

More importantly, any added collision boxes disappear on play:

Stopped: alt text

Playing: alt text

which I can't find any way to fix.

Here's the code for the component:

     void UProceduralWallComponent::GenerateWall(FVector Endpoint)
     AActor* owner = GetOwner();
     USceneComponent* root = NULL;
     if (owner)
         root = owner->GetRootComponent();
     if (!root)
     if (root->GetNumChildrenComponents() < 1)
     USceneComponent* child = root->GetChildComponent(0);
     float wallLength = Endpoint.Size();
     float width = child->Bounds.BoxExtent.Y*2/child->GetComponentScale().Y;
     FVector currentPoint = child->RelativeLocation;
     currentPoint.Y += width;
     TArray<USceneComponent*> clones;
     //clone first child of the root
     for (int i = 0; currentPoint.Y < wallLength; currentPoint.Y += width, ++i)
         USceneComponent* currentComp = CloneComponent(child->GetClass(), child->GetName() + FString::FromInt(i), child, root);
         if (!currentComp)
     //clone all children of the first child recursively
     CloneRecursive(child, clones);
 void UProceduralWallComponent::CloneRecursive(USceneComponent* parent, TArray<USceneComponent*> &parentClones)
     TArray<USceneComponent*> children;
     parent->GetChildrenComponents(false, children);
     if (children.Num() == 0)
     for (USceneComponent* child : children)
         int i = 0;
         TArray<USceneComponent*> childClones;
         for (USceneComponent* parentClone : parentClones)
             USceneComponent* clone = CloneComponent(child->GetClass(), child->GetName() + FString::FromInt(i), child, parentClone);
             if (GEngine)
                 GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Yellow, clone->GetName());
         CloneRecursive(child, childClones);
 USceneComponent* UProceduralWallComponent::CloneComponent(TSubclassOf<USceneComponent> CompClass, FString CompName, UObject* Template, USceneComponent* parent)
     FName name(*CompName);
     USceneComponent* newComp = ConstructObject<USceneComponent>(CompClass, GetOwner(), name, RF_NoFlags, Template);
     if (GEngine)
         GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Yellow, newComp->GetClass()->GetName());
     if (!newComp)
         return NULL;
     newComp->bCreatedByConstructionScript = true;
     if (newComp->bWantsInitializeComponent)
     if (parent->GetOwner())
     return newComp;

and the Blueprint calling it: alt text

Product Version: Not Selected
more ▼

asked Feb 21 '15 at 02:04 AM in C++ Programming

avatar image

11 2 3 5

avatar image Lojo Feb 21 '15 at 05:02 AM

I'm not sure if this is the answer to your problem, but I don't think you're supposed to be doing anything complex in the constructor. The constructors are invoked all the time in the editor. Do you have the same problem if you move your constructor logic to the BeginPlay event?

avatar image Dozeworthy Feb 21 '15 at 05:40 AM

If I move it to BeginPlay, the wall has gaps in for some reason, but more importantly, the purpose of the component is to make walls easier to build in the editor, so it needs to execute at construction time for any changes to be visible. It runs fast enough, so complexity isn't the issue, and it isn't conceptually much different to the video I linked, just more flexible.

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

2 answers: sort voted first

OK, looks like the problem was that the procedural components weren't being serialized. I just called the FinishAndRegisterComponent() method of the owning actor to fix it, instead of RegisterComponent(). Alternatively, making a UProperty TArray of USceneComponent pointers and adding all the procedural components to it also worked.

more ▼

answered Feb 23 '15 at 01:36 AM

avatar image

11 2 3 5

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

As far as i recall:

  • it's quite normal that the effect vanishes when you rebuild the BP. It gets then any modification to the actor to have the Costruction Script get fired again.

  • you can't have more than one collision box per component, even if not per actor (but maybe i'm wrong). If this is the case, you'll have to adapt and stretch your collision box to the new size.

more ▼

answered Feb 22 '15 at 02:32 PM

avatar image

391 17 12 32

avatar image Dozeworthy Feb 22 '15 at 11:58 PM
  • It doesn't vanish when rebuilding, the construction runs fine every time in the editor. It's just more likely for components to disappear when the level isn't saved, which doesn't happen for any other construction scripts I'm running.

  • I'm added additional components for each collision box, and I already have multiple blueprints with multiple collision boxed on them, and those work fine.

(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