Why does UpdateInstanceTransform() of GroupedSpriteComponent crash?

Hey guys!

I’m currently having a UPaperGroupedSpriteComponent rendering some sprites for me. I added some instances via

SpriteComponent->AddInstanceWithMaterial(FTransform(FRotator(0, 0, 0), points[idx], FVector::OneVector), Sprite, Material, false, colors[idx].ReinterpretAsLinear());

Now I want to change those instances’ transform. But the

FTransform NewTransform(NewRotation, NewTranslation, NewScale);

SpriteComponent->UpdateInstanceTransform(index, NewTransform);

always throws an exception, no matter what I do. Can someone please help, I really don’t know what I’m doing wrong :confused:
Thanks!

Post the logs. That might help narrow it down.

Hey Jin_VE,

thanks for your help! The log file produces:

[993]LogWindows: Error: === Critical error: ===

[993]LogWindows: Error:

[993]LogWindows: Error: Assertion failed: (Index >= 0) & (Index < ArrayNum)

[File:D:\Build++UE4+Release-4.18+Compile\Sync\Engine\Source\Runtime\Core\Public\Containers/Array.h][Line: 610]

[993]LogWindows: Error: Array index out of bounds: 0 from an array of size 0

So it seems that there can be no instances found… But I successfully created them and can see them in the editor as well? I don’t know what to change to get this correct…

The AddInstanceWithMaterial() function returns an index. Make sure that is good. If it is then the only possibilities I can think of are:

  1. the SpriteComponent pointer you added instances to isn’t the same SpriteComponent pointer you access later
  2. you are removing the instances or clearing the entire list somewhere

I’d debug the game and make sure the pointer address is the same in both spots. Sounds like you may have created a second component and overwrote the old pointer. But if not, keep the info coming and we’ll figure it out.

Hey Jin_VE, thanks you very much for your help! Right now I’m really desperate, because I just don’t know what is wrong. This is really annoying and I really have to get this to work :/… Anyhow, I debugged again my script and couldn’t find any problems. I create the component in the constructor using:

if(!SpriteComponent)
	SpriteComponent = CreateDefaultSubobject<UPaperGroupedSpriteComponent>(TEXT("PointCloudSpriteRenderer"));

The pointer is still alive when I access it and the UPaperGroupedSpriteComponent object has all the instances inside the instances array (however the “InstanceBodies” array is empty - this is, I think, because the instances have no physics enabled)… but still I don’t know what to do…

apparently the error is in line 109 of PaperGroupedSpriteComponent.cpp:

if (FBodyInstance* InstanceBodyInstance = InstanceBodies[InstanceIndex])
   [...]

so it has something to do with not having InstanceBodies, right?

I don’t know. I’ve never used this system. But there is a bool that turns the physics stuff on and off so I assume it’s optional. Try to get more info from the logs. Link the complete files.

You said the PerInstanceSpriteData array has the sprites you added?

If the problem is the body instance array then there are three possible reasons why it isn’t getting filled. In the function PaperGroupedSpriteComponent::SetupNewInstanceData(), it creates the body instance when “(bPhysicsStateCreated && (InSprite != nullptr) && (InSprite->BodySetup != nullptr))”.

So either you’re adding the sprite instance before the physics state has been created, the sprite pointer you’re passing in is null, or the sprite you passed in doesn’t have a body setup. Figure out which one it is and we can try to fix it.

hey Jin, thank you very much for your help! I really appreciate it that you tried to help me!

After endless digging through the engine code I think I kinda solved the problem and apparently you’re right; the problem is indeed that the Sprite I’m using has no BodySetup - so one has to turn on 3D Collision for the Sprite one is using in the Editor. OMG. This issue has really got me busy for days. I really have to say that Unreal really sucks regarding documentation and being buggy! Thanks again for the help though!

But it quite clearly is a bug, isn’t it? I mean, you should be able to change transforms even though the Sprite has no collision enabled, right?

I think you’re doing something wrong. I can create a component and add an instance without it breaking. I updated the transform too. Maybe look at the sprite you’re passing in. The one I created in the editor had the body setup by default.

Yeah. Edit the sprite asset and look in the “Collision” section. You want “Sprite collision domain” to be “Use 3D physics”.

Not necessarily. Even with the 3D collision enabled, you can set the collision profile to “No Collision” if you don’t want it. Now, crashing instead of giving an error/warning does qualify as a bug IMO. This is an “experimental” feature so Epic might appreciate it if you let them know.

And yeah, UE4 docs are pretty lacking. Also, any problem more complex than a beginner faces is next to impossible to locate on the web because all the beginners have flooded the system with inane questions. Google can’t cope so an expert almost never finds what they’re looking for.