Under review

Random Vector2 or Vector3

Shane Peterson 5 months ago in Game Creator updated by Marti (Lead Developer) 5 months ago 3


Is there an easy way to generate a random Vector2 or random Vector3? I'm trying to find a random point within a radius and set it to a variable however I can't seem to find the right kind of action to either create a new Vector or add values to a Vector.


Unity version:
Game Creator version:
Under review

Hi Shane;

Unfortunately, this is one of those cases where a custom Action would work great. Not sure if you know a bit of programming, but if you do, you can easily do it yourself by creating a custom Action (right click on your project -> Create -> Game Creator -> Developer -> Simple Action.

Edit the script and, inside the InstantExecute method, place the random value generator and assign it to a Local or Global variable. If you need help, let me know!

Thank you! I'm attempting that now. I started with the default random variable action as reference and it appears to be working. I am however getting an error that doesn't seem to prevent anything from working:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorWindow.Close () (at <17b72532ee2c4da1b6f632d3f1705fe0>:0)

Apart from running the random number twice and casting it to the X and Y of a new Vector2 it's identical to the default action so I'm not quite sure how to solve it.

Looks like something is giving you a null reference exception, but I can't see what. Either try restarting Unity and see if it's gone, or create a new thread with the entire log trace.