- Home /
Sprite Shadow Script Problem
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?
Answer by xxmariofer · Jan 17, 2019 at 11:40 AM
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.
Answer by Karbonic · Jan 18, 2019 at 01:53 AM
@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?
Your answer
Follow this Question
Related Questions
How do i change the GUI.Box font size and box size ? 0 Answers
How can i make the spaceship to land/take off with physics vertical ? 2 Answers
How can I loop over all vertices and draw triangles ? I'm getting out of range exception 1 Answer
How can I get the SerializedObject and FineProperty also the node tree childs of conversations ? 0 Answers