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"

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 :/ Thanks!

Product Version: UE 4.18
Tags:
more ▼

asked Nov 26 '17 at 01:20 PM in C++ Programming

avatar image

hausfrau87
134 4 6 16

avatar image Jin_VE Nov 26 '17 at 01:29 PM

Post the logs. That might help narrow it down.

avatar image hausfrau87 Nov 26 '17 at 04:31 PM

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..

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

2 answers: sort voted first

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?

more ▼

answered Nov 28 '17 at 11:55 AM

avatar image

hausfrau87
134 4 6 16

avatar image Jin_VE Nov 28 '17 at 05:01 PM

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.

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

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.

more ▼

answered Nov 26 '17 at 04:48 PM

avatar image

Jin_VE
4.5k 32 79 42

avatar image hausfrau87 Nov 27 '17 at 12:01 PM

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..

avatar image hausfrau87 Nov 27 '17 at 12:45 PM

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?

avatar image Jin_VE Nov 27 '17 at 10:05 PM

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?

avatar image Jin_VE Nov 28 '17 at 03:14 AM

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.

avatar image Jin_VE Nov 28 '17 at 02:18 PM

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.

avatar image Jin_VE Nov 28 '17 at 03:22 PM

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

(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