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"

Instanced static mesh component added through c++ performance problem

Hi guys, I have a c++ actor which has UInstancedStaticMeshComponent added with

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = GridFloor) in header file.

I created it in constructor, and updated it in PostEditChangeProperty with 2 for loop by X and Y two integer

So the InstacedStaticMeshComponent will be a grid with xsize * ysize.

When I change the size integer to 10*10 it takes almost 1~2 sec, and when i change it like 20*20,

the editor freezes like 10sec.

Below is part of my code

.h File

 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = GridFloor)
 class UInstancedStaticMeshComponent* GridFloor;

.cpp in Constructor

 GridFloor = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("GridFloor"));
 GridFloor->bCastDynamicShadow = false;
 GridFloor->CastShadow = false;

.cpp in PostEditChangeProperty

 for (int x = 0; x < XSize; x++)
     for (int y = 0; y < YSize; y++)
         FVector tmpTranslation(x*100.0f, y*100.0f, 0.0f);

I already have made same actor through Blueprint (not derive from c++ actor), and when Update it in Construction Script, it just works fine.

when i update the grid in beginPlay, it just fine but i need it in editor, not in-game

Is this a bug? or Did i wrong somewhere??

Product Version: UE 4.17
more ▼

asked Sep 13 '17 at 02:44 PM in C++ Programming

avatar image

Dongyun Jeong
1 1 3 4

avatar image Dongyun Jeong Sep 13 '17 at 03:23 PM

Ok, I comment out PostEditChangeProperty function, then derived a blueprint actor from my c++ class. In that blueprint class, I setup construction script with the inherited InstancedStaticMeshCompoentn, then its same. But, i added a new ISMComponent, then use it in construction script, it works fine. instant update with 30*30 grid. dont know why

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

1 answer: sort voted first

Hi Donyun Jeong Don' t use PostEditChangeProperty, instead use the equivalent Blueprint Construction Script in c++ is called OnConstruction:

 virtual void OnConstruction(const FTransform& Transform) {}

more ▼

answered Sep 13 '17 at 02:53 PM

avatar image

391 9 12 19

avatar image Dongyun Jeong Sep 13 '17 at 03:11 PM

I tried OnConstruction, but it's same. thank you for answer.

avatar image Nachtmahr Sep 13 '17 at 03:28 PM

ZkarmaKun is right. Maybe you forgot something? If you set a breakpoint in your code does it get called? Maybe need a Call to parent inside your Blueprint? Double check everything please =)

avatar image Dongyun Jeong Sep 13 '17 at 03:59 PM

Ok, I tried even more, but it doesnt work. the OnConstruction function is called, but each AddInstance() function in OnConstruction takes too long. almost 400~900 milisec on each call. So i deleted UPROPERTY() macro on ISMComponent in header file, then it works. don't know why but i'll digging from here. Thanks for reply, and sorry for my english.

(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