Search Unity

Simple movement example throw exception.

Discussion in 'Entity Component System' started by distantcam, Mar 23, 2018.

  1. distantcam

    distantcam

    Joined:
    Jun 20, 2015
    Posts:
    4
    So I'm playing around with ECS and am trying to set up a simple example of moving an existing GameObject (cube).

    I've added the GameObjectEntitiy, PositionComponent, HeadingComponent, MoveForwardComponent, MoveSpeedComponent, and CopyTransformToGameObjectComponent to my cube. I've set the heading to (0, 0, 1) and the move speed to 1.

    When I run this however I get the following exception.

    InvalidOperationException: The NativeArray CopyTransforms.entities must be marked [ReadOnly] in the job CopyTransformToGameObjectSystem:CopyTransforms, because the container itself is marked read only.
    Unity.Jobs.LowLevel.Unsafe.JobsUtility.ScheduleParallelForTransform (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters, System.IntPtr transfromAccesssArray) <0x3607b350 + 0x00072> in <a58d63d105984c39abb8652b638a76b1>:0
    UnityEngine.Jobs.IJobParallelForTransformExtensions.Schedule[T] (T jobData, UnityEngine.Jobs.TransformAccessArray transforms, Unity.Jobs.JobHandle dependsOn) (at C:/buildslave/unity/build/Runtime/Jobs/Managed/IJobParallelForTransform.cs:58)
    Unity.Transforms.CopyTransformToGameObjectSystem.OnUpdate (Unity.Jobs.JobHandle inputDeps) (at C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.11/Unity.Transforms.Hybrid/CopyTransformToGameObjectSystem.cs:54)
    Unity.Entities.JobComponentSystem.InternalUpdate () (at C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.11/Unity.Entities/ComponentSystem.cs:353)
    Unity.Entities.ScriptBehaviourManager.Update () (at C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.11/Unity.Entities/ScriptBehaviourManager.cs:82)
    Unity.Entities.ScriptBehaviourUpdateOrder+DummyDelagateWrapper.TriggerUpdate () (at C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.11/Unity.Entities/ScriptBehaviourUpdateOrder.cs:59)

    How do I fix this?
     
  2. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    this is your answer
     
  3. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    The problem I believe, is that the 'CopyTransformToGameObjectSystem' script is provided with the ECS.
     
  4. distantcam

    distantcam

    Joined:
    Jun 20, 2015
    Posts:
    4
    Yes, all of those components are part of Unity's ECS. I didn't write them.
     
  5. mike_acton

    mike_acton

    Unity Technologies

    Joined:
    Nov 21, 2017
    Posts:
    110
    I’ll have to take a look.
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Any ideas? As I see EntityArray in Job does not change and ReadOnly attribute should not interfere

    Code (CSharp):
    1. [ComputeJobOptimization]
    2.         struct CopyTransforms : IJobParallelForTransform
    3.         {
    4.             [ReadOnly] public ComponentDataFromEntity<Position> positions;
    5.             [ReadOnly] public ComponentDataFromEntity<Rotation> rotations;
    6.             public EntityArray entities;
    7.  
    8.             public void Execute(int index, TransformAccess transform)
    9.             {
    10.                 var entity = entities[index];
    11.  
    12.                 if (positions.Exists(entity))
    13.                 {
    14.                     transform.position = positions[entity].Value;
    15.                 }
    16.                 if (rotations.Exists(entity))
    17.                 {
    18.                     transform.rotation = rotations[entity].Value;
    19.                 }
    20.             }
    21.         }
     
    Last edited: Apr 18, 2018
  7. mike_acton

    mike_acton

    Unity Technologies

    Joined:
    Nov 21, 2017
    Posts:
    110
    Yes that should just be readonly. It'll be changed in the next package update, I'm sure - but in the meantime you could probably just edit locally.
     
    eizenhorn likes this.
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Yes, I did, I created my MyCopyTransformToGameObjectComponentWeNeedMoreLettersInTitle :D