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"

Cooking UInstancedStaticMeshComponent Created at Runtime

Running into a slight problem when cooking an instance of an actor that contains UInstancedStaticMeshComponent that was created in OnConstruction. The cook always crashes at line 1595 of InstancedStaticMesh.cpp with means my PerInstanceRenderData isn't valid.

The creation of the component itself looks like this.

 InstancedStaticMeshComponent = NewObject<UInstancedStaticMeshComponent>(this);
 InstancedStaticMeshComponent->SetFlags(RF_Public | RF_Standalone);
 InstancedStaticMeshComponent->RegisterComponent();
 InstancedStaticMeshComponent->SetStaticMesh(StaticMeshParameter.StaticMesh);
 InstancedStaticMeshComponent->SetCollisionProfileName(TEXT("WorldStatic"));
 InstancedStaticMeshComponent->SetMobility(EComponentMobility::Static);
 InstancedStaticMeshComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetIncludingScale);


The StaticMesh comes from a struct which contains a bunch of options for which mesh to display, and any transformation randomization that may happen on that static mesh instance. I've tried various flags in the SetFlags function thinking that was perhaps my problem to no avail.

Product Version: UE 4.20
Tags:
more ▼

asked Aug 17 '18 at 03:12 PM in C++ Programming

avatar image

HailstoneRyan
714 39 26 54

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

1 answer: sort voted first

Solved my own problem. Code below for anyone who runs into the same thing.

 InstancedStaticMeshComponent = NewObject<UInstancedStaticMeshComponent>(this, NAME_None, RF_NeedPostLoad);
 InstancedStaticMeshComponent->SetStaticMesh(StaticMeshParameter.StaticMesh);
 InstancedStaticMeshComponent->SetCollisionProfileName(TEXT("WorldStatic"));
 InstancedStaticMeshComponent->SetMobility(EComponentMobility::Static);
 InstancedStaticMeshComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetIncludingScale);
 InstancedStaticMeshComponent->RegisterComponent();
 InstancedStaticMeshComponent->ConditionalPostLoad();
more ▼

answered Aug 17 '18 at 04:22 PM

avatar image

HailstoneRyan
714 39 26 54

(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