Hello Guest

Author Topic: Prefab/Material problem  (Read 3780 times)

sleekdigital

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Prefab/Material problem
« on: January 07, 2013, 07:13:28 pm »
I'm trying to make 2 prefabs for each of my sprites, one that is affected by fog and one that isn't.  So I duplicated the material of my sprite collection and assigned a shader that has fog enabled (set to mode global)  Then I duplicated a prefab (made from a 2dtk sprite) in my scene, renamed it, and chose Game Object > break prefab instance. then I replaced the material with the fog enabled material on that game object.  And then I dragged that into my project tab to make it a new prefab.  So all looks well in my project tab, I have a prefab with the original material and a prefab with my fog enabled material.  But, when I drag the fog enabled prefab into the scene, it reverts back to having the original material!!  I tried this same procedure with a cube and this issue did not occur, so I am guessing it is related to 2dtk.  Any thoughts?  Also it seems I can work around the problem by reverting to prefab value, but it is still a bit annoying.  Hoping I am just doing something wrong here.

Update:  Actually the workaround doesn't help, when i start the game it changes back to the original material.  :(
« Last Edit: January 08, 2013, 02:16:49 am by sleekdigital »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab/Material problem
« Reply #1 on: January 08, 2013, 04:27:28 am »
It will revert to the original material for various reasons. Why don't you use multiple materials directly from the sprite collection? http://unikronsoftware.com/2dtoolkit/doc/tutorial/multiple_materials_in_a_sprite_collection.html

This will let you create 2 sprites with the same texture, and then apply 2 different materials to them. You don't have to create prefabs, but you can if you want to.

sleekdigital

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Prefab/Material problem
« Reply #2 on: January 08, 2013, 01:18:17 pm »
I was concerned that this would double the size of my atlas if I have to create 2 sprites with each texture, but it seems that adding the same texture tot he collections just creates a new sprite and reuses the same one in the atlas, so... cool, thanks!
« Last Edit: January 08, 2013, 01:25:39 pm by sleekdigital »