Hello Guest

Author Topic: REQUEST: "Material overrides" for sprites (kinda technical)  (Read 3406 times)

MindsEye

  • Newbie
  • *
  • Posts: 4
    • View Profile
REQUEST: "Material overrides" for sprites (kinda technical)
« on: April 10, 2017, 01:46:59 am »
Hi! I've been using 2D toolkit for quite a while with my game Blast Brawl 2 (Steam link: http://store.steampowered.com/app/447980). 2D Toolkit is GREAT, much better than current standard 2D support in unity, but I have a few requests for tweaks/additions that would be extremely useful in certain situations.

This is (I think) my last suggestion, and it's by far my most niche/technical. (I totally understand if it's rejected lol)

Anyway: when adding more complicated mechanics to my game, I implemented a system to "override" the material of a sprite.

Examples:
  • a character is frozen in ice, so I stop their current animation and give them a version of their normal material that adds an "ice filter" effect.
  • Or, a character gets set on fire, so they are overriden with a "charred" filter.
  • Space ship covered by a pulse shield? Filter.
  • Stealth mode? Filter.
  • etc etc

Other 2D toolkit developers may appreciate the feature, so I figured I would suggest it here. Also, the code to do this it is actually surprisingly easy to do! (I can provide it if it would make this more likely to be implemented.)

So:

REQUEST: Please allow dynamic material overriding in a generic way.
In short, it would be nice to be able to add code in tk2dBaseSprite (thus adding the feature to all other sprite types) that allows developers to set a material that is null by default.

If the material is NOT null, the sprite's mesh material is set to that material instead of the one defined on the sprite. (Setting the material back to null reverts the material to the sprite's default obviously.)

Honestly, the largest change I would suggest making is adding a material field in the sprite editor to allow developers to control this material from the inspector. Since this is a fairly programmatic-centric change tho that's not even necessary.

Also: In my implementation, I do a little bit extra. When setting the override sprite, developers can specify if they want the final material set to match the primary texture on the default sprite material. I have some small code that manages a static list of materials/clones and cleans up them to handle textures. This is potentially outside of the intended scope of 2d toolkit, but it allows much more generic materials to be used across a wide variety of sprites at basically no performance impact.



That's basically it! Honestly this feature has proven way more useful in practice than I expected it to, since it gives you a really efficient/direct method to do certain effects. Again, this totally makes sense as an out-of-scope feature, but it's actually not that much code in my implementation so I thought it might be worth it to suggest.

Cheers!