# Sprite Shadow Script Problem

**URL:** https://discussions.unity.com/t/sprite-shadow-script-problem/219086
**Category:** Questions & Answers
**Created:** [January 17, 2019, 11:02am UTC](https://discussions.unity.com/t/sprite-shadow-script-problem/219086 "2019-01-17T11:02:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Karbonic](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/karbonic/32/907245_2.png) [@Karbonic](https://discussions.unity.com/u/Karbonic)
#### Post date: [January 17, 2019, 11:02am UTC](https://discussions.unity.com/t/sprite-shadow-script-problem/219086/1 "2019-01-17T11:02:19Z")

</div>

Hello.  
I’ve been using this script to cast dynamic shadows with sprites for a while now.  
However, with one of the new updates, it has become outdated, and needs something to be fixed.

```
using UnityEngine;
using System.Collections;

public class SpriteShadows : MonoBehaviour {

	// Use this for initialization
	void Start () {
		Renderer renderer = GetComponent <Renderer>();
		if (renderer == null)
			Debug.Log ("Renderer is empty");
		GetComponent<Renderer>().shadowCastingMode = 
				UnityEngine.Rendering.ShadowCastingMode.On;
		GetComponent <Renderer>().receiveShadows = true;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

```

When I go to test, I get the error message “GetGfxDevice() should only be called from the main thread”  
Followed by a crash.  
Can anyone point me in the right direction to fix this and get the script up to date?

---

<div class="post-metadata">

### Author: ![xxmariofer](https://avatars.discourse-cdn.com/v4/letter/x/e9bcb4/32.png) [@xxmariofer](https://discussions.unity.com/u/xxmariofer)
#### Post date: [January 17, 2019, 11:40am UTC](https://discussions.unity.com/t/sprite-shadow-script-problem/219086/2 "2019-01-17T11:40:59Z")

</div>

I have tested your code and worked fine for me, are you using threads? cause from threads you cant call most of unity methods, and thats what your error is saying, but Start method is never going to be call from a thread so it is a bit extrange.

---

<div class="post-metadata">

### Author: ![Karbonic](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/karbonic/32/907245_2.png) [@Karbonic](https://discussions.unity.com/u/Karbonic)
#### Post date: [January 18, 2019, 1:53am UTC](https://discussions.unity.com/t/sprite-shadow-script-problem/219086/3 "2019-01-18T01:53:22Z")

</div>

@xxmariofer  
Hmm.  
What shader are you using for the sprite?  
Beforehand I had to use a legacy shader to make this work,  
but something may have changed in the update.  
I don’t believe I’m using threads. Can I see a screenshot of how you have it set up?
