Odd Problem with Physics and Instantiating.

Hello.

We are working with Unity on a small game that takes physical input from the real world, and converts it coordinates and angles inside the game.

However, we have come across a small problem when trying to instantiate objects based on these coordinates and angles. Basically, our code looks like this:

		Vector3 o = new Vector3 (xcoord,ycoord,GameObject.Find("Main Camera").camera.nearClipPlane);
		Vector3 p = GameObject.Find("Main Camera").camera.ViewportToWorldPoint(o);
		GameObject disc;
		disc = (GameObject)Instantiate(GameObject.Find("Saucer"), p, Quaternion.identity);
		disc.GetComponent("discmotion").SendMessage("setXangle", xAngle);
		disc.GetComponent("discmotion").SendMessage("setYangle", yAngle);
		disc.GetComponent("discmotion").SendMessage("applyForce");
		Destroy(disc, 20);

However, every once in a while, whilst attempting to instantiate a new disc, Unity comes up with the following error:

PhysicsSDK: createActor: WriteLock is still acquired. Procedure call skipped to avoid a deadlock!
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)

Subsequently, I also get an error telling me that

m_Actor == NULL

and lastly a null reference error, possibly when I try to set these values subsequently. The first error message refers specifically to the instantiate line.
This does not only not spawn a new disc, but also crashes unity. Any suggestions as how to fix it?

(oh, and please don’t mock my naming conventions! This is still WIP :slight_smile:

the null reference exception usually means that the instansiatedobject has been deleted make sure that the original object has not been deleted by accident.

As was already suggested, make sure “Saucer” is being found, is fully init’d and ready for use.

Do you always have that call to ‘Destroy()’ in there? Are you sure your not Destroying the object your trying to later use?

Lastly, where/when is all this setup taking place? The ‘Awake’ event? The ‘Start()’ event? Try moving it to a later and later time (Awake->Start->1st Update) and see if that helps.

Well, the destroy command is in there to destroy the disc after a while. The error popped up, even before I put that line of code in there.

As far as Saucer goes, it is fully available, and ready to use.

The function is called every time we receive a set of coordinates from our input device (we’re building it using a tangible acoustic interface, basically), and it basically just clones the original objects, and propels it from the screen, based on these coordinates.

According to the very limited amount of google hits I get on this error message, it is related to the physics, but I am unsure on how to restructure the program in order to currently continue.

the ‘addforce’ function merely adds torque and force to the gameobject.

I know this is an old thread, see here:

http://forum.unity3d.com/viewtopic.php?p=143631#143631

Ta

JT