Hi, I’ve downloaded your project and it’s so cool, but it turned out to be pretty inneficient in big and medium tilemaps as you are doing a getComponent in a update and also you are creating and destroying lots of Gameobjects. I’ve made some changes.
First, in my tilemap your script generated like +200 GameObjects, so I’ve added a field to limit the number of shadows/GameObjects a tilemap can cast, this is per tilemap, it’s not a static field.
Then, at the start of the script (Awake) I create maxShadowNumber PathShadows, and as I create them I store them in a List, so you can access then without having to iterate the childs of the transform and call getComponent for every of them
Then I’ve added a field to control how much the script updates per second, I actually update it 2 times per second.
In every update, the script filters the closest “colliders” to the camera of all the compositecollider2d colliders, I store then in a List<List>. Then I iterate the PathShadows List and I Call path.SetSize with every List point of the List<Lists> points.
As path shadows inherits from ShadowCaster2D, the shadow paths updates automatically, so you only create some shadow casters and updates them every some time. This way works much better.
I’ve also fixed a little mistakei in getLayers method, propCount has to be increased in each iteration, not inside the if, so I just removed the field and used the iterator i variable instead.
I’ll do a pull Request to your repo so you can check the changes
I also want to ask you if I could (or you) upload this as s free asset to the unity store. It’s still kinda beta but I think it can be already used. It only becomes problematic when there are more than 64 shadow caster in total, but I think it’s normal, at the end they are 64 GameObject with ShadowCasters2D, nothing to do there