Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Weird behaviour of injected Camera gameobject's transform

Discussion in 'Entity Component System' started by Curlyone, Apr 11, 2020.

  1. Curlyone

    Curlyone

    Joined:
    Mar 15, 2018
    Posts:
    41
    Hello

    I am trying to make a raycast system to move my character around.

    I put Convert And Inject script on my camera gameobject and put CopyTransformToGameObject component to my entity in an authoring component.

    In my system's OnUpdate method i am taking the active camera and do ScreenPointToRay and pass the information i take from new input system, but the thing is.. camera's transform is not updated even tho in hiearchy camera's transform is updated properly. So for some weird reason when i do cam.transform it only takes initial values.. its like system is using 'snapshot' of camera's initial transform, therefore raycasting doesnt work properly.

    Also even more weirder, i am using this code in game state MB singleton for testing for this

    Code (CSharp):
    1.     private void Update()
    2.     {
    3.         Debug.Log(campaignCamera.transform.position);
    4.     }
    5.  
    6.     public Ray RequestRay(Vector2 vector2)
    7.     {
    8.         Debug.Log(campaignCamera.transform.position);
    9.         return campaignCamera.ScreenPointToRay(vector2);
    10.     }
    Log inside Update is working properly but Log inside RequestRay(which is called inside my raycast system's OnUpdate function) is still Logging initial values.

    And even more weirder:
    I am using rotate and zoom system for camera(both system's execution's results are reflected to inspector properly), zoom system's execution doesnt change the 'snapshot' values of camera's initial transform, but when i use rotate system it DOES change that snapshot's values,

    for example if my camera gameobject's initial position was 10, 10, 10, zoom system doesnt change these values but rotate system makes it like 9,11,10 etc..

    I am using Entities 0.9 and 2020.1.0b5.
     
  2. Curlyone

    Curlyone

    Joined:
    Mar 15, 2018
    Posts:
    41
    Alright i figured it out, it was because of the Simple Camera Controller script, i removed it and it works fine now *Awkwardly moves on*