Search Unity

Assets/AI Scripts/UFO.cs(17,35): error CS1612: Cannot modify a value type return value of `UnityEngi

Discussion in 'Scripting' started by The-Game-Master, Sep 1, 2014.

  1. The-Game-Master

    The-Game-Master

    Joined:
    Aug 6, 2014
    Posts:
    54
    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!
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You are doing:
    Code (csharp):
    1. transform.position.x = someNumber;
    (or similar)

    To fix it:
    Code (csharp):
    1. Vector3 pos = transform.position;
    2. pos.x = someNumber;
    3. transform.position = pos;
     
    The-Game-Master likes this.