Search Unity

Clearing missing something stupid

Discussion in 'Entity Component System' started by bugfinders, Oct 4, 2019.

  1. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,811
    OK so, i know this is stupidly basic and clearly Im doing something stupidly wrong, but even looking at the samples, recreating the rotating cube something hasnt worked and I cant see it

    So, new project, add entities and all the bits that come with, add in 1 cube at 0,0,0 set camera so cube is in the middle and start work

    I added a convert to entity script with default settings
    I made 2 scripts based off the examples, added the cubedata to my cube and set degrees per second to 180

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Unity.Entities;
    5. using Unity.Mathematics;
    6. using UnityEngine;
    7.  
    8. public class CubeData : MonoBehaviour,IConvertGameObjectToEntity
    9. {
    10.     public float DegreesPerSecond;
    11.  
    12.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    13.     {
    14.         var data = new RotationSpeed_ForEach { RadiansPerSecond = math.radians(DegreesPerSecond) };
    15.         dstManager.AddComponentData(entity, data);
    16.     }
    17.  
    18.  
    19. }
    20.  
    21. [Serializable]
    22. public struct RotationSpeed_ForEach : IComponentData
    23. {
    24.     public float RadiansPerSecond;
    25. }
    and

    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3. using Unity.Transforms;
    4. using UnityEngine;
    5.  
    6.  
    7. public class RotatorSystem : ComponentSystem
    8. {
    9.     protected override void OnUpdate()
    10.     {
    11.         Entities.ForEach((ref RotationSpeed_ForEach rotationSpeed, ref Rotation rotation) =>
    12.         {
    13.             var deltaTime = Time.deltaTime;
    14.  
    15.             rotation.Value = math.mul((rotation.Value), quaternion.AxisAngle(math.up(), rotationSpeed.RadiansPerSecond * deltaTime));
    16.         });
    17.     }
    18. }
    So the million dollar question is why is it not rotating about the centre?? Untitled Project.gif
     
  2. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    That code looks Ok.
    So there is definitely another system affecting your data.
    Are you sure there isn't any other systems that you have done that are touching any of the transform data (LocalToWorld/Translation/Rotation)?
    Also you could/should do the above code in a JobComponentSystem where you can take advantage of Jobs and Burst.
     
  3. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,811
    Nope it is a 100% blank project as described there are 2 files, and the cube, thats it

    thanks for the tip, I was copying the first example in the hellocube example.. I am aware there are other ways to do it, I get the ecs principal, just not seeing how I am getting this stupid example wrong
     
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Well, i've just copied your code and it just works fine on my end.
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    It looks like your cube has the RotationSpeed and is attached to an empty parent that also has a RotationSpeed.
     
  6. schaefsky

    schaefsky

    Joined:
    Aug 11, 2013
    Posts:
    90
    I had a similar looking problem once where the problem was related to parenting, ie. my box was a child of another game object and was not at 0,0,0 in relation to that parent, which made it seem to rotate in weird ways.
    Do you only have the cube or is their any parent/chil relationship going on?
     
  7. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,811
    Nope just the cube. I did try parenting it, to try and offset the issue, but didnt make it any better, if anything it made it worse
     
  8. schaefsky

    schaefsky

    Joined:
    Aug 11, 2013
    Posts:
    90
    I tried as described, works for me. There must be something about your cube.
     
  9. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,811
    I thought about that, but I did as I described so, as I say, im at a loss which is why I came here. My cube is very much 1 cube, nothing done to it.
     
  10. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Is it a Unity cube or your own mesh? Maybe you have the mesh pivot wrong?
     
  11. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,811
    It is a standard unity cube, as described and I have not moved the pivot. Hence Im so confused
     
  12. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Why don't you just export your scene / project
     
  13. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,811
    I will do when I am home again.. As clearly from here everyone is under the impression all should have worked
     
  14. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    590
    I'm new to DOTS, so I'm probably also doing something wrong, but I can't get it to work at all. I add both of your scripts into a project that already has Entities, Burst, etc. New scene, add a cube at 0,0,0, add the CubeData script to the cube and set rotation to 180. Put a Convert To Entity script on the Cube.

    With the default settings for Convert To Entity 'Convert and Destroy', the cube disappears. With 'Convert and Inject' the cube is there, but does not rotate.

    Am I leaving out a step?
     
  15. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Install Hybrid Rendering package
     
  16. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    590
    Yep. It works as expected now, rotates around it's center pivot. I can't imagine what you are doing that would make it behave like that. I'm using 2019.3.0b5
     
  17. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,811
    Well.. Im back. and despite previously making 5 different projects trying to work out why it was being wonky.... it now works.. you know those times where you just want to shout and scream and swear people mess with your stuff? this is me