Ahh ok - well that is much better than a whole tons of square casters (I tested that haha). I’d say that is a lot better than what I had misunderstood that it was doing
I also had trouble editing the shadows after generation, and I am thinking it may be an issue with the new experimental 2D lighting, although I didn’t spend a lot of time testing that out.
I think if somebody could solve that (if its even possible) rather than destroying and recreating on changes… and rather just updating the existing ones and creating new/destroying if needed, it would probably be far more performance friendly.
I’ve been trying to solve the same situation. The best case would be splitting the tilemap into chunks so that anytime something needs updated you are only updating a part of everything. Unfortunately the TilemapCollider doesn’t let you get a sub section of the tilemap. Instead you will have to iterate over the tilemap and create the shadow geometry yourself. Unity also doesn’t provide a top level update method when a tile is changed. You can use TileBase::RefreshTile() to receive these updates but it requires all tiles to derive a custom base class. I find all of this super unclean.
For my own purposes I’ve transitioned over to using Super Tilemap Editor as they already chunk the tilemap. It’s easy enough to expose these chunks and throw your own scripts onto them, they also provide a proper update method so you know when something is modified.
Having said that I’ve found some troubling things about the current state of the Unity 2D lighting system.
Lighting doesn’t render when working inside of a prefab.
Shadows don’t work with edges, only full polygons.
Shadows are made by transforming the meshes, which results in cases where the shadow won’t reach the end of the light. I found personally many scenes just looked bad due to this current problem.
Lights are culled properly, however for every light drawn every single shadow caster is drawn regardless of where it exists or even touches a light. Huge potential performance hit depending on your scene.
I’ve already started writing my own 2d lighting/shadowing method to solve these issues. Here is the github if anyone is interested.
i too have noticed these. the latter can be worked around by having a larger area but steeper falloff on the light.
i chose the unity lighting solution for my project because i hope for future improvements and a lot of resource availablr if i find myself in trouble. also, free assets tend to not satisfy my needs in many cases. that happened with tilemaps. while the build in tilemap system is okay, i encounter lots of problems in usability all the time.
on the subject of dynamically editing them, i can only say smth about the generation of shadowcasters: my method stores a reference to the instantiated prefab in a 2d array whose indices correlate with world position; so it would be very easy to dynamically adjust JUST the shadowcaster you want, splitting it or merging with its neighbours just like i do elsewhere in the script. maybe a similar tapproach could be applied to your solutions.
Very cool, I noticed though you mention LWRP a couple times - but I assume this is using the new Universal Render Pipeline rather than the outdated LWRP right?
Ah sorry, Unity’s rendering has evolved quickly I’m still thinking in old terms. Yes the code is build as a ScriptableRenderFeature and only relies on the Universal RP. I changed the documentation to match that so not to cause more confusion.
Is this already solved in 2019.3?
I’m not very well versed in Unity, but this appears in the Roadmap for 2019.3 and I do not understand if it has been addressed or not:
shadows arent. my work on tgis has entirely been in unity 19.3. For normal maps i use a simple material with a flat normal map, so to make vertical objects in my 2d space, including walls painted on a tilemap, selfshadow when light is “behind” them (thinking pseudo 3d).
BirdiePeep, your solution is amazing! It’s a shame it does weird things when I rotate objects and play with the Spread parameter (a “back light” appears).
If I only apply the required -90 rotation in the X axis in order for the light to appear in the scene, nothing unusual happens, but the spread is not oriented the way I want. I will have to use colliders to simulate the spread.
I’m hoping you guys are still active on this thread, I’m struggling to follow and get the shadows appearing…
I’ve managed to get the shadow casters going - following thomasdw’s edit to “ShadowCaster2D” and the MDReptile’s “SetTileMapShadows” script. However, after many hours of trying to figure it out - I still can’t get the shadows to appear.
All my tilemap objects are in Grid>Objects, and I attached the Tilemap collider 2D (used by composite), Composite Collider 2D, ShadowCaster2D, and SetTilemapShadows - still no use.
Although each shadow_caster_… spawns with a ShadowCaster2D script, the shadows don’t appear at all for any of the 14 casters…
edit: i was about to recommend my own solution becaus its easy to debug, but looking at your screenshots i dont think it works for you at all, as it only generates quads.
its very strange you dont have shadows at all, on first glance everything looks to be setup correctly. i had “incorrectly” generated casters when i tried it; but the casting of shadows at all was never an issue. maybe someone else has an idea whats going on here.
edit2: [quote=“BirdiePeep, post:22, topic: 772801, username:BirdiePeep”]
hadows don’t work with edges, only full polygons.
[/quote]
i dont know if this could be relevant but try setting your composite colliders geometry type to polygons. howevery its beyond me how this could affect the script youre using just a stab in the dark.
Hey, robbel! Thanks for the suggestion - but it doesn’t seem to have any effect…
A quick note I should mention:
When the “ShadowCaster2D” and “SetTilemapShadows” scripts on the Grid>Object are active, my shadow on the TV stops working as well. When I disable the two scripts again, then the shadow works on the TV… Not sure what that means
Hi, I didn’t know this thread existed so I started a new one with my 2 cents:
I think it does not make sense to copy everything here but I can do it if you want.
This script is intended to work in edit-time, and does not create new colliders, just new GameObjects with ShadowCaster2Ds.