I am currently implementing the bullet shooter function for my game. When the shoot button is pressed, a new bullet is instantiated, and given the position of the player. Problem is when I call the instantiate function and pass it the position of the player using transform.position the bullet does not get copied. when I call the instantiate function using just a new vector like new Vector3(0,0,0) it works perfect and another bullet is copied. Why does passing it the position of the player break it?
If the original bullet is indeed a reference to an existing GameObject or to a prefab asset, then your first Instantiate should be creating a clone of the bullet. Add EditorApplication.isPaused = true; just after it, and then look around your Hierarchy to see if it made a new instance.
Yes a new copy does appear in the hierarchy, but only when a new vector is use. When I pass the transform.position, no new object appears in the hierarchy.
I don’t see how that’s possible. There’s only five overloads for Instantiate, transform.position is a Vector3 property, and Vector3 is a struct so there’s no wiggle room for type hacks.
Can you try Vector3 p = transform.position; and then use p as your second argument to Instantiate()?
And in general, start putting in some Debug.Log() statements to show that you got inside an if block, and what the values you’re working with are.
Debug.Log($"Going to clone {bullet} at {transform.position}");
I figured out the problem. the bullet layer was set to destroy itself when it collided with the player layer. as soon as the copy was created, it was Destroye