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"

Instanced Static Mesh

Hi all I'm playing around with instanced static meshes and now when I initialize and create everything in constructor and create my instanced static mesh with call to "CreateDefaultSubobject" everything works as intended the instance is created and I can add instances of static meshes, I would like to move this code away from constructor and execute it in BeginPlay() method however I encountered a problem the "CreateDefaultSubobject" can be called only in constructor so I'm using "NewObject" to create InstancedStaticMeshComponent the instance is created successfully I can set a static mesh on it, however when I call "AddInstance" passing in transform the exception is thrown I've investigated a bit and it seams that it is thrown because the OwnerActor is nullptr here a code

Code From Constructor this works fine

 instancedMeshesComponent = CreateDefaultSubobject<UMyInstancedStaticMeshComponent>(*tempName);
 instancedMeshesComponent->AttachTo(RootComponent);
 
 instancedMeshesComponent->SetStaticMesh(MeshType); // MeshType is set to cube
 
 FTransform transform;
 transform.SetLocation(FVector(0, 0, 0));
 
 instancedMeshesComponent->AddInstance(transform);
 

Code from BeginPlay this doesnt work the exception is thrown at "AddInstance(transform)" line also I'm not sure what I should pass in as the "Outer" argument so I just pass in current level but I've tried to pass in "World" and also the StaticClass() of the object where instancedStaticMesh is declared no changes

     instancedMeshesComponent = NewObject<UMyInstancedStaticMeshComponent>(GetWorld()->GetCurrentLevel(),*tempName);
     instancedMeshesComponent->AttachTo(RootComponent);
     
     instancedMeshesComponent->SetStaticMesh(MeshType); // MeshType is set to cube
     
     FTransform transform;
     transform.SetLocation(FVector(0, 0, 0));
     
     instancedMeshesComponent->AddInstance(transform); // exception is thrown at this line
Product Version: UE 4.11
Tags:
more ▼

asked May 28 '16 at 02:16 PM in C++ Programming

avatar image

Mlody "Swidwin"
327 12 11 25

avatar image Mlody "Swidwin" May 28 '16 at 04:44 PM

Right passing in "this" pointer as Outer argument solved a half of the problem now it doesn't throw exception but the mesh is not rendered

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

1 answer: sort voted first

I was having the same issue. Looks like you need to add

 instancedMeshesComponent->RegisterComponentWithWorld(GetWorld());

to get it to appear

more ▼

answered Jan 14 '19 at 07:52 PM

avatar image

fgeorg-oculus
1 3

(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