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"

Update component TArray after editor changes

Hey guys! I'd like to update a TArray with the right number of UInstancedStaticMeshComponent when I change a value in the details panel.

For now, I can get the TArray to be initialized with the expected number of components when we look at the default values assigned to variables in the header. But then, when I change the values of those same variables in the editor, the TArray of components is not updated accordingly. Here is some code:

 in the header:
 
 private:
 UPROPERTY(VisibleAnywhere, Category = "Instanced Mesh")
         TArray<UInstancedStaticMeshComponent*> GridMeshChunks;
 
 public: UPROPERTY(EditAnywhere, Category = "Grid Properties", meta = (ClampMin = "1", ClampMax = "10", UIMin = "1", UIMax = "10"))
         int gridLength = 2;
     UPROPERTY(EditAnywhere, Category = "Grid Properties", meta = (ClampMin = "1", ClampMax = "10", UIMin = "1", UIMax = "10"))
         int gridWidth = 2;
     UPROPERTY(EditAnywhere, Category = "Grid Properties", meta = (ClampMin = "1", ClampMax = "10", UIMin = "1", UIMax = "10"))
         int gridHeight = 2;
 
 in the .cpp
 
 AGridManager::AGridManager()
 {
     PrimaryActorTick.bCanEverTick = true;
 
     bReplicates = true;
     bAlwaysRelevant = true;
 
     int chunkNum = gridLength*gridWidth*gridHeight;
 
     GridMeshChunks.Empty();
 
     for (int i = 0; i < chunkNum; i++)
     {
         FString name = "GridMesh" + FString::FromInt(i);
         GridMeshChunks.Add(CreateDefaultSubobject<UInstancedStaticMeshComponent>(*FString(name)));
     }
 
     RootComponent = GridMeshChunks[0];
     for (int i = 1; i < chunkNum; i++)
     {
     GridMeshChunks[i]->SetupAttachment(RootComponent);
     }
 }


So, in this case, I obtain an array with 8 UInstancedStaticMeshComponents. Nothing happens when I change the value in-editor. I believe for something to happen I'd need to add something to the OnConstruction script. I tried to create the components similarly in that function but I couldn't find a way to make it work without crashes. Any pointers or tips?

Product Version: UE 4.19
Tags:
more ▼

asked Jun 02 '18 at 05:19 AM in C++ Programming

avatar image

Xylord
41 9 13 15

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I had a similar problem recently. You need to implement the PostEditChangeProperty event. Then you should be able to handle variable changes in the editor. https://answers.unrealengine.com/questions/252811/how-do-i-use-posteditchangeproperty.html

more ▼

answered Jun 02 '18 at 10:26 AM

avatar image

PascalSantos
46 4 9

avatar image Xylord Jun 03 '18 at 01:03 AM

Thanks for the answer! I got the rest of the way from there.

 void AGridManager::PostEditChangeProperty(struct FPropertyChangedEvent& e)
 {
     Super::PostEditChangeProperty(e);
 
     FName PropertyName = (e.Property != NULL) ? e.Property->GetFName() : NAME_None;
 
     if (PropertyName == GET_MEMBER_NAME_CHECKED(AGridManager, gridLength))
     {
         int chunkNum = gridLength*gridWidth*gridHeight;
         nodeNumber = chunkNum*FMath::Pow(chunkSize, 3);
 
         for (int i = 0; i < GridMeshChunks.Num(); i++)
         {
             GridMeshChunks[i]->DestroyComponent();
         }
 
         GridMeshChunks.Empty();
 
         for (int i = 0; i < chunkNum; i++)
         {
             FString name = "GridMesh" + FString::FromInt(i);
             GridMeshChunks.Add(NewObject<UInstancedStaticMeshComponent>(this, *FString(name)));
             //GridMeshChunks.Add(CreateDefaultSubobject<UInstancedStaticMeshComponent>(*FString(name)));
         }
 
         RootComponent = GridMeshChunks[0];
         for (int i = 1; i < chunkNum; i++)
         {
             GridMeshChunks[i]->SetupAttachment(RootComponent);
         }
     }
 }

This function allows me to change the size and contents of my array on the go. However, the actual components under the hierarchy tree of the actor don't match up with the array. It looks like I'd need to run another function so the SetupAttachment functions take effect. Any ideas?

(comments are locked)
10|2000 characters needed characters left
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