Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] Variable not marked as readonly?

Discussion in 'Entity Component System' started by Extrys, Mar 13, 2020.

  1. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    343
    So i was using the entities foreach as everyday and i noticed this error
    InvalidOperationException: <>c__DisplayClass_OnUpdate_LambdaJob0.Data.targetTranslation is not declared [ReadOnly] in a IJobParallelFor job. The container does not support parallel writing. Please use a more suitable container type.
    Unity.Jobs.LowLevel.Unsafe.JobsUtility.CreateJobReflectionData (System.Type wrapperJobType, System.Type userJobType, Unity.Jobs.LowLevel.Unsafe.JobType jobType, System.Object managedJobFunction0) (at <94c5f4c38cdc42d2b006f8badef04394>:0)
    Unity.Entities.JobChunkExtensions+JobChunk_Process`1[T].InitializeParallel () (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/IJobChunk.cs:235)


    I was doing this just for testing
    upload_2020-3-13_12-23-59.png

    The problem is that i can not add the Attribute [ReadOnly] to a local variable
    is for that im getting that error

    doing it using a job solves the problem
    but i want to know if im doing something wrong or if exists some other way to doing it using ``Entities.Foreach``
    upload_2020-3-13_12-47-5.png



    Also in the new Entities version it says this:
    upload_2020-3-13_12-49-51.png
    then it should be possible, or i missunderstood the Changelog, if so please also tell me that this really means

    Thanks
     

    Attached Files:

  2. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    396
    You need to use
    .WithReadOnly(targetTranslation)
    when scheduling using lambda syntax
     
    insominx and Extrys like this.
  3. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    343
    Ohh i didnt notice that extension, thanks a lot its working now!