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. 

Array filled in OnConstruction is empty on next call

I am attempting to create a usable list of scenecomponents for a user to select one in an array.

I have created a struct, FComponentListItem:

 struct FComponentListItem
     UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Component")
     USceneComponent* ComponentInQuestion;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Selection")
     bool bSelected;

And I have created another struct with a TArray of these structs on an ActorComponent called InteractionComp.

In my actors OnConstruction function, I call a function on InteractionComp that finds all usable scenecomponents on the actor and then creates an FComponentListItem struct and copies in the appropriate information. This should then be usable by the user. Unfortunately, I can't find a way to populate this array in a meaningful way.

 void UInteractionComp::OnConstruction(const FTransform& Transform)
     if (ComponentListMaster.Num() < 1)
         TArray<UActorComponent*> Components = GetOwner()->GetComponents().Array();
         for (auto& Component : Components)
             FComponentListItem Item;
             Item.ComponentInQuestion = Cast<USceneComponent>(Component);
             Item.bSelected = false;

Every time this code runs, (ComponentListMaster < 1) returns true, even if the list was populated with 5 members in the previous run.

Product Version: UE 4.12
more ▼

asked Jul 28 '16 at 08:38 PM in C++ Programming

avatar image

51 8 10 15

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

1 answer: sort voted first

A few items of feedback:

  • I don't think this fixes the problem, but if you're using FComponentListItem in blueprints, it should have USTRUCT(BlueprintType).

  • How is ComponentListMaster declared? If not marked with UPROPERTY, the value may get reset when your object is duplicated (e.g. when play starts).

  • When you play the game in editor, all actors are copied before play. That's why when an actor is moved or changed in-game, it is reset when you exit PIE. If you expect changes from play mode to persist back to the editor, you're going to need a cleverer approach.

  • How is your Actor's OnConstruction method defined? Are you sure it's calling UInteractionComp::OnConstruction?

more ▼

answered Jul 29 '16 at 01:52 AM

avatar image

Digi Labs Dan
566 16 11 34

avatar image Tiskahar Jul 29 '16 at 04:43 PM

I typically omit certain code snippets to make these more readable.

I had BlueprintType in the USTRUCT macro and had removed it wondering if that was causing the issue. There is no change.

The ComponentListMaster is initialized as so:

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Master")
 TArray<FComponentListItem> ComponentListMaster;

and the OnConstruction is defined as:

 void OnConstruction(const FTransform& Transform);

This was defined before I knew that ActorComponents don't get an OnConstruction function, so I had to tie it to an interactable actor that could call the function. I had plenty of logging in it, so I know that it's being called correctly.

As for PIE, this is all being done in map setup, and I am not playing the map when I change. All values are being changed in details panel.

Thank you for the reply!

(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