Assets/AI Scripts/UFO.cs(17,35): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable

Assets/AI Scripts/UFO.cs(17,35): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable

What does this error mean and how do I fix it?
Thanks in advanced!

Are you trying to modify one of the components of the position? For example:

gameObject.transform.position.z = 5;

This is not valid, you need to assign a full Vector3 to the position if you want to change it:

gameObject.transform.position = new Vector3(gameObject.transform.position.x, 5, gameObject.transform.position.y);

The error actually does a good job of explaining. You are trying to modify a Vector3 struct directly. You need to either make a copy or create new, making a copy and modifying the values in c# is typically the route. This applies to c# as unityscript does all the heavy lifting for you when the code is built out.

In your code you’re doing something like(I mean it would be helpful if you actually included the location of the error in the code, so you get something made up.)

///... Code.. blah
///... in some method(update maybe? location doesn't matter).
/// You're doing:
///... foo
someGameObject.transform.position.x = 30.0f;
someGameObject.transform.position.y = 3.0f;

/// or something like that, but you can't, Vector3's need to be copied or instantiated to replace.

// Get copy and modify.
Vector3 someCopy = someGameObject.transform.position;
someCopy.x = 30.0f;
someCopy.y = 20.0f;
someCopy.z = 10.0f;
// Stuff it back into the position property.
someGameObject.transform.position = someCopy;

Did you write something like:

transform.position.x = 3.0f;

To change the x value(for example) of the position vector, you need to do:

transform.position = new Vector3(3.0f, trasnform.position.y, transform.position.z);

Note that I assume you’re using C#, because I think(unable to check at the moment) unityscript allows that, unlike C#.