2D Sprite Texture Animation - SetTexture or SetTextureOffset

I’m working on a rather simple Animation2D class that’ll let me cycle through textures or frames on a material. I’ll be using it as the basis of a 2D sprite-based game.

My question is whether it would be more efficient to use Material.SetTextureOffset() or Material.SetTexture() to cycle through my frames. The former would use a spritesheet and would have a list of indexes to cycle through, while the latter would have a list of textures to cycle through. While I’m thinking the former is more efficient, it’s not as easy to use in the editor. You’d have to provide for image size, frame columns/rows, etc. as well as follow some sort of chart for setting the indexes. With the latter, you just drag your individual frame textures into the list in the inspector, which would be great for my artist friend to be able to easily build his own sprites and get them to me in a package or whatever.

animatedMaterial.SetTexture("_MainTex", textures[currentIndex]);
// or
animatedMaterial.SetTextureOffset("_MainTex", frames[currentIndex]);

A smaller and less important question:
Which would be better, using Update and Time.deltaTime or FixedUpdate and Time.fixedDeltaTime to measure the time between frames? Time between frames is a float currently set through a fps variable in the editor.

timeSinceLastFrame += Time.fixedDeltaTime;
// or
timeSinceLastFrame += Time.deltaTime;

if (timeSinceLastFrame >= timeBetweenFrames)
    //...

[Third small question found myself, will omit]

Thanks!

(1) Sure just move the texture around, so SetTextureOffset

(1B … ?) Would it be sensible to just use 2DToolkit? it saves say 2 man years of work on any such project. he’s completely figured out all the draw call blah blah and you just drop things in, it is unbelievably easy

(2) “which is better update or fixedupdate” what do you mean … to do what ??? You’d have to explain.

{To some extent, my answer to this is “You should never have to use either for any purpose!”)

“FixedUpdate is for physics only” … (it’s funny how many people say that!) I would say rather, if you’re doing physics, you should do that in fixedupdate (for the straightforward reason that it happens a certain number of times per frame, rather than “incredibly fast” and indeed “at various unknown speeds” as it would happen in update)

{A classic problem is someone asks “hey my game/car/whatever runs at different speeds on different platforms!” the answer is immediately "dude you accidentally used update rather than fixedupdate somewhere}

{To repeat, again ideally you SHOULD NOT EVEN EVER have to use physics in that way!! think more like a simulate and less like an animator. (Sounds like a slogan!) Just set off an explosion or something and let PhysX sort it out.}

so, I’d perhaps say there’s no sense in which FU is “for physics only”. it’s “for” anything you need to do, well, on the frame rate. physics, generally, needs to be done in F.U. – well at any rate, you can do it however the hell you want, so long as you understand that a physics step needs to happen in some measured certain time

“you should have as little info in FixedUpdate as possible” Why ?? I don’t see that … I mean “your game should run well” and if there’s some problem "you’ll have to optimise

That’s my understanding anyway ! Cheers!

(3) You’re third question … um, yes you were right! :slight_smile: