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. Dismiss Notice

Follow Entity in Scene View

Discussion in 'Entity Component System' started by zardini123, Jun 5, 2020.

  1. zardini123

    zardini123

    Joined:
    Jan 5, 2013
    Posts:
    68
    What is the quickest method to get the scene view camera to follow an entity with a Translation (plus a Rotation) component?
     
  2. zardini123

    zardini123

    Joined:
    Jan 5, 2013
    Posts:
    68
    Has nobody else tried having the Scene View camera follow an Entity yet?
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    IDK if the SceneView camera can follow an entity, but the game camera can through proxy:
     
  4. mmpneo1

    mmpneo1

    Joined:
    Jun 17, 2015
    Posts:
    2
    You also can "convert and destroy" camera itself, and work with it in systems.
     
  5. zardini123

    zardini123

    Joined:
    Jan 5, 2013
    Posts:
    68
    Thank you @Lurking-Ninja. Yeah, though my question is in regards to the Scene View camera only. I have not been able to find much information regarding the Scene View camera following an Entity.
     
  6. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    In all seriousness, I suspect this might not be possible yet. Your want for it is valid, and the usage case is important. But since DOTS still doesn’t have wide support for things like skinned animation, I imagine controlling the scene camera has not been prioritized, if it’s come up internally at all.
     
  7. shmafoo

    shmafoo

    Joined:
    Nov 22, 2016
    Posts:
    24
    It's actually quite easy but I did only a quick test:

    Code (CSharp):
    1. public class SceneViewCameraMovement : SystemBase
    2. {
    3.     protected override void OnUpdate()
    4.     {
    5.         Entities.ForEach((ref Translation t, in MovementX m) =>
    6.         {
    7.             // Return in case the scene view tab is closed
    8.             var sceneView = SceneView.lastActiveSceneView;
    9.             if(sceneView == null)
    10.                 return;
    11.  
    12.             // Move the test object
    13.             var position = t;
    14.             position.Value.x += m.Value;
    15.             t = position;
    16.  
    17.             // Update the scene view camera
    18.             sceneView.LookAt(position.Value); // You can also use LookAtDirect which does not "animate" the movement
    19.         }).Run();
    20.     }
    21. }
     
    JakHussain and PublicEnumE like this.