below: this is inside Update(); I am trying to add spheres as soon as someone presses a key, at the location of the object (the "player") Snippet: Code (csharp): // add bullet! var sph = GameObject.FindGameObjectWithTag ("sphere_prefab"); Instantiate (sph, transform.position, transform.rotation); print(transform.rotation); 1. the print line results in the correct rotation value 2. the prefab is found. Error: nullReferenceException for the Instantiate line. Why? I really can't see the problem here. Entering "transform.rotation" is the same as Quaternation.identity, right? Is this Quaterstuff part of transform (subclass)?
When you say 'the prefab is found', do you mean you've checked that .FindGameObjectWithTag() is returning a valid reference, or do you mean that you've looked in the project and the prefab is there? If it's the latter, try adding... Code (csharp): if(kubus == null) Debug.Log("kubus prefab not found"); ...after the .FindGameObjectWithTag() line. I find it a bit odd that you're using .FindGameObjectWithTag() for this purpose anyway. If it were me, I'd add 'var kubusPrefab : GameObject;' at the top of the script and drag the prefab into the appropriate slot on the object in the inspector. Having done that, you'd be able to just do 'Instantiate(kubusPrefab, ...);' instead of having to look up the prefab with .FindGameObjectWithTag() every time you fire. Quaternions are rotations, so transform.rotation is a quaternion. Quaternion.identity is a special value which means 'the default rotation' or 'no change in rotation', depending on what you're doing with it.
Thanks Neil! You are right that I am using a weird method (finding the other object), but I really have to get used to the wonderful idea that the editor "sees" my variables and makes it possible to throw objects in those variables.