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"

UInstancedStaticMeshComponent ::RemoveInstance Bug

Hi all,

I'm currently facing a strange behavior when I call RemoveInstance from C++.

Basically I need to remove only one instanced static mesh at time, I managed to remove the correct one but for some reason the last instance mesh disappears but It's collisions are still there (I can walk on hit but It's not visible), then the more instances I remove the more this behavior gets worse, for example some meshes appears again and ohers are visible but without collision. I can post images or videos if needed;

So here's the code called by the Player Tick function, it's a basic linetrace:

     FHitResult Hit;
 
     FVector StartTrace = FirstPersonCameraComponent->GetComponentLocation();
     FVector EndTrace = (FirstPersonCameraComponent->GetForwardVector() * Range) + StartTrace;
 
     FCollisionQueryParams CollisionParams;
     CollisionParams.AddIgnoredActor(this);
 
     GetWorld()->LineTraceSingleByChannel(Hit, StartTrace, EndTrace, ECollisionChannel::ECC_WorldDynamic, CollisionParams);
     
     ABlock* IsBlock = Cast<ABlock>(Hit.GetActor());
     if (IsBlock == NULL)
     {
         CurrentBlock = nullptr;
         return;
     }
 
     CurrentBlock = IsBlock;
     CurrentBlockIndex = Hit.Item;    // Maybe this cause all the problems?


Then when the player press the left mouse button this code is executed:

 if (CurrentBlock != nullptr)
     CurrentBlock->BreakBlock(CurrentBlockIndex);

ABlock.cpp

 #include "Block.h"
 
 
 // Sets default values
 ABlock::ABlock()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = false;
 
     ISM_Block = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("Terrain"));
 }
 
 // Called when the game starts or when spawned
 void ABlock::BeginPlay()
 {
     Super::BeginPlay();
     
     /**
       Here I simply place the cubes on the map, they are all 100x100 
      */
     for (int i = 0; i < 5; i++)
     {
         for (int j = 0; j < 5; j++)
         {
             FTransform transform(FRotator(0.0f, 0.0f, 0.0f), FVector(i*100.0f, j*100.0f, 0.0f), FVector(1.0f, 1.0f, 1.0f));
             SM_Block->AddInstance(transform);
         }
     }
  
 }

 void ABlock::BreakBlock(int32& index)
 {
     ISM_Block->RemoveInstance(index);
 }



I tried to implement an array of integers that holds a reference of the instances spawned by following this image that i found on the Live Training of the Instanced Static Meshes by Epic and then removing elements from that array whenever i call RemoveInstance but unfortunately nothing changed, sometimes the editor even crashed (let me know if you want me to post the code with the array implemented). alt text

I already posted a question here: Link and there's the possibility that there is a bug in the RemoveInstance function.

This is another test made by user Nachtmahr:

Link

Link

In the last example every red box has no Collision regardless if mesh is visible or not.

UPDATE

I installed the 4.16.3 and then created a new C++ project using the FPS Template, I used the same exact code from the example above and it works without any problem, I can now assume that is a bug present only in the 4.17 version.

Product Version: UE 4.17
Tags:
more ▼

asked Aug 28 '17 at 12:05 AM in Bug Reports

avatar image

Hyne_
16 1 5

avatar image AzGoalie Sep 01 '17 at 04:42 AM

I have the same issue :(

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

1 answer: sort voted first

Same here, UInstancedStaticMeshComponent is broken in 4.17.1. I'll make a minimum project with repro steps and will post it separately, without Hyne_'s custom code, so it's easier for UE devs to track it.

edit: here is it: https://answers.unrealengine.com/questions/704641/bug-instanced-static-mesh-component-is-broken-in-4.html

more ▼

answered Sep 08 '17 at 10:24 PM

avatar image

Flashback
91 2 6 9

avatar image Matthew J Sep 15 '17 at 06:06 PM

Thank you for making that post, Flashback. It seems that this issue is already set to be resolved in 4.18, by looking at the post that you created. As such, I'll be marking this issue as resolved. If anyone has any questions, please refer to the other post as it would be best to keep all information in one place.

(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