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"

Simple InstancedMeshComponent example 4.92

Hey there,

Im currently trying to create a 3d hexgrid. Right now the only thing I got working is to have an actor with a bunch of staticMeshcomponents which all have a Hexagon model. The performance is awfull to say the least. So I did some googling and learned about Unreal's "UInstancedStaticMeshComponent".

I spend the last couple of hours trying to figure out how to use this component but no luck so far. I can find some people with similar problems in different topics, but the only solutions I found were meant for blueprints, not C++ coding.

So my questions, could someone please post a very simple example script on how you create an AActor with multiple UInstancedStaticMeshComponent? Or maybe point me in the right direction because I'm just stuck.

Edit: I've managed to get the component working to such a point where I can see a list in the inspector of all the instances. However, not appears in the viewport.

 AHexGridGenerator::AHexGridGenerator()
 {
     PrimaryActorTick.bCanEverTick = true;
 
     meshComponentBase = NewObject<UInstancedStaticMeshComponent>(this, TEXT("Base Cell Mesh (Used to create instances)"));
     meshComponentBase->SetStaticMesh(GridInfo.StaticMesh);
     meshComponentBase->RegisterComponentWithWorld(GetWorld());
     meshComponentBase->AttachTo(RootComponent);
     AddOwnedComponent(meshComponentBase);
  
     for (int i = 0; i < 5; i++)
     {
         meshComponentBase->AddInstance(FTransform(FVector::ZeroVector));
     }

}

But when I look in the inspector and select the "meshcomponentbase" it shows that there's no static mesh linked to the component. So for some reason

meshComponentBase->SetStaticMesh(GridInfo.StaticMesh);

doesn't appear to work.GridInfo is a UStruct I created which I use to set the grid width, height and default model for a hex. This method worked perfectly when creating a bunch a ordinary staticMeshComponents so I don't see why it should be a problem here.

Product Version: UE 4.9
Tags:
more ▼

asked Oct 25 '15 at 05:19 PM in C++ Programming

avatar image

ThomSip
26 1 2 2

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

0 answers: sort voted first
Be the first one to answer this question
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