Search Unity

Bug Camera position not updating

Discussion in 'Scripting' started by instinct46, Sep 12, 2020.

  1. instinct46

    instinct46

    Joined:
    Nov 19, 2017
    Posts:
    4
    Unity Information:
    • 2020.1.5f1 Personal
    • Universal Render Pipeline

    I have a script which is attached to the main camera object. I found that updating the position does not update the camera position. To test it wasn't me I left the update method as the following and it still does not update.

    Code (CSharp):
    1. void Update()
    2.     {
    3.         Camera.main.transform.position = Camera.main.transform.position + Vector3.left;
    4.     }
    The console isn't showing any errors and the breakpoints are being hit.
    As I was typing this I had a thought to change the position while playing in the inspector. When changed, it automatically flips back to the original position.

    **Turned out the default camera created with the "Universal Render Pipeline" has a "simple camera controller" which was causing the issue.
     
    Last edited: Sep 12, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Do you have any animations on the camera? Animations will override scripting.

    Make a blank scene and put the above on the camera... it should go FLYING off to the left at extremely high speed. If you do not have objects in the scene, there will be no visible change, since the skybox is infinitely far away, obviously.
     
  3. instinct46

    instinct46

    Joined:
    Nov 19, 2017
    Posts:
    4
    Turned out the default camera created with the "Universal Render Pipeline" has a "simple camera controller" which was causing the issue. I removed the script and all was good. Not sure why it's part of the default camera for new projects. I'll have to read up on why it's there, but for now it's gone :D.
     
    tillscherrer and Kurt-Dekker like this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Good to know. I hadn't used this yet so I shall keep it in mind for the future. Thanks for followup.
     
  5. FahimFuad

    FahimFuad

    Joined:
    Jul 27, 2020
    Posts:
    26
    Try doing camera works in LateUpdate......see if it works or not
     
  6. instinct46

    instinct46

    Joined:
    Nov 19, 2017
    Posts:
    4
    @RDX65, I'll give it a crack in the morning (from a template new build). **edit** it's installing now, will be able to tell you in about 15 minutes.
     
  7. instinct46

    instinct46

    Joined:
    Nov 19, 2017
    Posts:
    4
    I just tried with the same logic in the original question attached to the main camera. It failed.

    Again fixed if I remove the simple camera controller.

    Version: 2020.2.0b2.3094