Antoshidza / NSprites-Foundation

Basic assets for working with NSprites package
MIT License
65 stars 17 forks source link

Ability to choose number of frames in an animation #8

Closed meditatingsloth closed 11 months ago

meditatingsloth commented 11 months ago

I have a sprite sheet that isn't completely filled out (5 slices on a 3x2 grid), however I noticed the animation system expects to use all slices of a grid. On the surface it seems trivial to limit the number of frames the system tries to run through, this is what I tried:

However, I noticed an empty frame still renders. Any idea what I might be missing?

Antoshidza commented 11 months ago

If your frameCount is limited to durations array length then frameIndex should also looped between 0 and frameCount - 1 inclusive, which means empty frame shouldn't be rendered.

Have you debug actual frameCount in SpriteUVAnimationSystem.cs ?

meditatingsloth commented 11 months ago

Yes, everything looks fine in the debugger with frameIndex.value (loops 0-4 as expected) and framePosition looks to be set correctly on each loop as well (never reads the 2,1 position as expected).

Antoshidza commented 11 months ago

Looks weird, I'll try the same as soon as I can to find a problem

Antoshidza commented 11 months ago

I do the same. change line, remove validate and change animation asset and all works. I actually have no idea yet because as you mentioned you see proper values in debug but still wrong result in scene.

Can you show your texture sheet? And also do you use shader from foundation or implement your own?

Also try to save project before enter playmode, because it could be something wrong with how unity react to animation asset changes. Though for me all works with opened subscene.

meditatingsloth commented 11 months ago

That is strange indeed. Thanks for checking. I'm going to try it again in a fresh project, maybe the old package is cached or something as I originally had this repo installed before updating to my fork. I've attached the sprite I'm using to test as well in case that makes a difference.

Also yes, I'm using the default "Regular" material/shader from NSprites

ship1

meditatingsloth commented 11 months ago

I'm able to replicate the flickering in a fresh project: https://github.com/meditatingsloth/Sandbox

A couple notes:

Antoshidza commented 11 months ago

I had to update the Renderer2D URP asset to a normal Renderer URP (the one that's created with the 2D URP template does not work with NSprites it looks like)

Yes, for Renderer2D URP you should implement compatible shader.

Will try it with your project.

Antoshidza commented 11 months ago

I've found out that all this time UV calculations was wrong, because 0.0 it seems starts from left bottom point instead left up point. So index 2 of our 5 frames pointing to last frame in texture sheet (which have 5 index). I've fixed it in this commit.

meditatingsloth commented 11 months ago

I've found out that all this time UV calculations was wrong, because 0.0 it seems starts from left bottom point instead left up point. So index 2 of our 5 frames pointing to last frame in texture sheet (which have 5 index). I've fixed it in this commit.

Ahh I didn't even think of that, thank you for looking into it!