Hello Guest

Author Topic: Prefab sprite overriding tilemap sprite  (Read 4360 times)

LaserDinosaur

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Prefab sprite overriding tilemap sprite
« on: September 07, 2014, 06:07:09 pm »
I'm using a tilemap with some prefabs as per http://www.unikronsoftware.com/2dtoolkit/docs/latest/tilemap/tutorial.html.

I have a wall that has special properties which I turned it into a prefab so I can attach a script and set the collider as a trigger. The problem is because the sprite is now part of the prefab it overwrites the sprite used in the tilemap. That means if I placed the tile (through the tilemap editor) in a flipped-horizontal, flipped-vertical or rotated position, it's lost when the game starts.

Is there a way to use a prefab in a tilemap but let the tilemap sprite take priority?

Cheers!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab sprite overriding tilemap sprite
« Reply #1 on: September 08, 2014, 12:41:17 pm »
Its not possible to get it to use the tilemap sprite, but you can make it rotate / flip your sprite if you want. It doesn't do that by default as it really really screws up performance due to breaking batching.

tk2dTileMapBuilderUtil.cs - instance.transform.localPosition = pos;
Thats where it sets the position, you can make it set the scale too if you want.

LaserDinosaur

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Prefab sprite overriding tilemap sprite
« Reply #2 on: September 14, 2014, 09:00:29 pm »
Thanks for the reply.

So I added in a few extra lines of code to the class you mentioned. I'm now getting the tile flags and flipping the prefab sprite if needed. That seems to work pretty well.

However I'm wondering if you could expand on your point "It doesn't do that by default as it really really screws up performance due to breaking batching".

If I'm only doing this on maybe 20-30 prefabs in the world, is it still a bad idea to do this? What is it about flipping the prefab that causes the batching to break? I did some quick tests and didn't notice the draw calls increasing.

Cheers!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab sprite overriding tilemap sprite
« Reply #3 on: September 14, 2014, 10:19:07 pm »
20-30 objects should be fine, but Unity (used to? not tested in a while) broke dynamic batching when you had non uniform scales.