#Missing shadows from a Light 2D - Spot on a tilemap with Composite Collider 2D.

1 messages · Page 1 of 1 (latest)

faint pewter
#

I hope this is the right place for this question. I'm working on a top down 2D game, I made my tilemap, and created some walls. I have a Light 2D Spot on my player GO, and I want it to cast shadows as the player moves around. On my tilemap I added a shadowcaster 2D, Tilemap Collider 2D, and a Composite Collider 2D component. Some of the time the light from the player casts shadows exactly as expected, but sometimes, usually based on the direction the player is facing the shadows just disappear. I'm fairly new to rendering in Unity, and I'm really lost as to figuring out how to get this working. I'm including 2 screenshots with the shadow working as expected, then I turned and the shadow disappeared.
Thanks in advance.

faint pewter
#

I wanted to just put an update, and an extra example of what's going on. I created a separate empty game object, added a box collider 2D, and a shadow caster 2D component. I placed it on in my scene, and as you can see the shadows appear and disappear as I turn and move around.

stark walrus
faint pewter
#

I'm sorry, I don't understand which gizmos you want turned on.

stark walrus
#

The yellow gizmos of the light. You got it right. I just want to see them when the issue actually happens.

faint pewter
#

the gizmos only show up in scene mode, so I had to switch back and forth. hopefully that let's you see what you wanted.

stark walrus
#

From the look of it, the shadow is rendered in the scene view even when it is not visible in the game view.

#

Is your light positioned in the same plane(same z pos) as the shadow casters and receivers?

faint pewter
#

Well, after you asked your question I started messing with the settings. Maybe you can give me some guidance on what these should be. I think most are obvious, with the exception of shadow_fix_1, which is the invisible cube that I'm using to test the shadow casting.

#

I might have just realized why I was breaking things when I changed settings around... my Main camera, and Light 2D are children of the player.

#

What I posted is basically normal, and shows the same behavior as before.

faint pewter
stark walrus
# faint pewter

I assume that you're rotating the Player object, so there no point looking at the light transform. Look at the player transform when the issue happens. Does it seem to have rotation on x/y or moved on z axes? Does the camera have rotation changed at some point?

faint pewter
#

Ya the rotation is on the player object transform... And the camera is a child of the player. I guess looking at my code for how I'm doing the rotation could be involved. Not that I'm doing much of anything fancy. Ya I'll take a look tomorrow to see if the z position is changing unexpectedly. Thanks!

faint pewter
#
//if right mouse button is pressed
        if (Input.GetMouseButton(1))
        {
            if (lastMousePosition == Vector3.zero)
            {
                lastMousePosition = Input.mousePosition;
                return;
            }

            float deltaX = Input.mousePosition.x - lastMousePosition.x;

            //float rotationAmount = deltaX * RotationSpeed * Time.deltaTime;
            float rotationAmount = deltaX * RotationSpeed;

            transform.Rotate(0f, 0f, -rotationAmount, Space.Self);

            lastMousePosition = Input.mousePosition;

        }
        else
        {
            lastMousePosition = Vector3.zero;
        }```
#

visually in the inspector I don't see transform.z changing at all when I rotate between the problem and it working normal.

faint pewter
#

Some changes I made. I added a debug message to the console if the player transform.z was ever not 0, and so far I have not seen that happen. Also I wanted to see if I could re-create the same problem by leaving the player alone, and moving the objects. which I was able to. So it has nothing to do with the player moving or rotating specifically.

stark walrus
#

What objects? The shadow casters?

faint pewter
#

Yes,

#

Unless you have other ideas, I'm thinking upgrading unity from 6.1 to 6.2, and updating visual studio might be worth a try.

stark walrus
#

I don't think visual studio has anything to do with it.
I'd double check again with the scene and game tab both open at the same time to see if the scene view also bugs out at the same time or not. If it doesn't, this is very likely an issue with the objects(shadow casters or the shadow receivers) orientation/position/rotation relative to the camera.

faint pewter
#

if that's the case, what's the solution?

stark walrus
#

The solution would be to prevent the change in the mentioned properties.

faint pewter
#

Ok, I finally finished updating unity, and things so far actually look good! 🎉 With the small exception that at a certain distance the shadows are not casting. I'm guessing there is some setting to determine how far away to cast shadows? Would you happen to know what that is?

#

I'm wondering if something was just broke with my unity install? Everything so far is working just as it should. So happy!

stark walrus
stark walrus