How to instantiate object on trasform.position

I want to instanstiate a public gameObject on the transform.position of the object that calls the intantiation with a script. I have this:

public GameObject explosionFX;

Vector2 moleculePos = transform.position;
Instantiate(explosionFX, moleculePos);

However I get an error on the second moleculePos saying: cannot convert from Vector2 to Transform. What should I have instead?

The two-argument version of Instantiate requires that the second argument is a Transform.

If you want to have that second be a position, you must ALSO include a third argument, the rotation. Adding a third argument of Quaternion.identity should fix your issue.

You can always look at example code in the docs for Instantiate(). :slight_smile:

1 Like

Oh I see Kurt. I did not know. Now it works. Thanks!