Search Unity

Burst error BC1028: Creating a managed array `byte[]` is not supported

Discussion in 'Entity Component System' started by Abbrew, Apr 23, 2021.

  1. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    I'm creating a Guid for each system to use, making sure to do it statically. Here's an example which creates COMBAT_AIMING_FROM_FOE_LOS_LAUNCHED_CHECK_TRAJECTORY_EVENT_TYPE_ID
    Code (CSharp):
    1. using System;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Jobs;
    5. using Unity.Mathematics;
    6. using Unity.Transforms;
    7. using UnityEngine;
    8. using static CombatAimingFromFoeLOSLaunchedCheckTrajectoryMessageSystem;
    9.  
    10. public class CombatAimingFromFoeLOSLaunchedCheckTrajectoryMessageSystem : EventMessagePhysicsQuerySystemBase<CombatAimingFromFoeLOSLaunchedCheckTrajectoryMessage>
    11. {
    12.     private static readonly float DX_STEP_LENGTH = 1.5f * EnvironmentMeasurements.METER;
    13.  
    14.     public static readonly Guid COMBAT_AIMING_FROM_FOE_LOS_LAUNCHED_CHECK_TRAJECTORY_EVENT_TYPE_ID = Guid.NewGuid();
    15.  
    16.     protected override void OnEventStream(NativeArray<CombatAimingFromFoeLOSLaunchedCheckTrajectoryMessage> messages)
    17.     {
    18.         var eventWriter =
    19.             messageQueueSystem.CreateEventWriter<EventInstance>();
    20.  
    21.         var environment = Environment.Get().GetData();
    22.         var obstructionMask = environment.GetIndestructible();
    23.         var topOfEnvironment = environment.GetTopOfEnvironment();
    24.         var collisionWorld = buildPhysicsWorld.PhysicsWorld.CollisionWorld;
    25.  
    26.         var eventTypeId = COMBAT_AIMING_FROM_FOE_LOS_LAUNCHED_CHECK_TRAJECTORY_EVENT_TYPE_ID;
    27.  
    28.         var numMessages = messages.Length;
    29.  
    30.         Job
    31.             .WithReadOnly(collisionWorld)
    32.             .WithCode(() =>
    33.             {
    34.                 for (var i = 0; i < numMessages; i++)
    35.                 {
    36.                     var message = messages[i];
    37.                     var userEntity = message.userEntity;
    38.  
    39.                     var weaponEntity =
    40.                         GetComponent<ItemUserActiveItemComponent>(
    41.                             userEntity
    42.                         ).activeItemEntity;
    43.                     var magazineEntity =
    44.                         GetComponent<GunWeaponItemMagazineHolderComponent>(
    45.                             weaponEntity
    46.                         ).magazineEntity;
    47.                     var launchAngleDegrees =
    48.                         GetComponent<AmmunitionLaunchPayloadComponent>(
    49.                             magazineEntity
    50.                         ).launchAngleDegrees;
    51.                     var gunReleasePointEntity =
    52.                         GetComponent<GunWeaponItemReleasePointComponent>(
    53.                             weaponEntity
    54.                         ).releasePointEntity;
    55.                     var gunReleasePointPosition =
    56.                         GetComponent<LocalToWorld>(
    57.                             gunReleasePointEntity
    58.                         ).Position;
    59.  
    60.                     var targetPosition =
    61.                         GetComponent<CombatAimingTargetComponent>(userEntity).targetPosition;
    62.                      
    63.                     var horizontalDistance =
    64.                         math.distance(gunReleasePointPosition.xz, targetPosition.xz);
    65.  
    66.                     var launchVelocity = PhysicsHelper.CalculateLaunchVelocity(
    67.                         gunReleasePointPosition,
    68.                         targetPosition,
    69.                         launchAngleDegrees
    70.                     );
    71.  
    72.                     var unobstructed = true;
    73.                     /*
    74.                         * Cast rays from the world top to the trajectory to see
    75.                         * if anything is taller than the trajectory and therefore
    76.                         * obscuring it
    77.                         */
    78.                     for(
    79.                         var distanceAlongLaunchTrajectory = 0f;
    80.                         distanceAlongLaunchTrajectory < horizontalDistance;
    81.                         distanceAlongLaunchTrajectory += DX_STEP_LENGTH
    82.                     )
    83.                     {
    84.                         var pointAlongTrajectory = PhysicsHelper.PositionAtDistanceBetweenLaunch(
    85.                             gunReleasePointPosition,
    86.                             targetPosition,
    87.                             launchVelocity,
    88.                             distanceAlongLaunchTrajectory
    89.                         );
    90.                         var pointAtCeiling = pointAlongTrajectory.WithY(topOfEnvironment);
    91.  
    92.                         var obstructionRequest = new LineOfSightRequest
    93.                         {
    94.                             start = pointAtCeiling,
    95.                             end = pointAlongTrajectory
    96.                         };
    97.  
    98.                         var obstructionResult = LineOfSightHelper.FindOne(
    99.                             obstructionRequest,
    100.                             obstructionMask,
    101.                             collisionWorld
    102.                         );
    103.  
    104.                         if (!obstructionResult.exists)
    105.                         {
    106.                             unobstructed = false;
    107.                             break;
    108.                         }
    109.                     }
    110.  
    111.                     // fire off an event
    112.                     eventWriter.Write(new EventInstance
    113.                     {
    114.                         eventTypeId = eventTypeId,
    115.                         sourceId = message.SourceId,
    116.                         success = unobstructed
    117.                     });
    118.                 }
    119.             })
    120.             .WithBurst()
    121.             .Schedule();
    122.  
    123.         messageQueueSystem.AddJobHandleForProducer<EventInstance>(Dependency);
    124.     }
    125.  
    126.     public struct CombatAimingFromFoeLOSLaunchedCheckTrajectoryMessage : IEventMessage
    127.     {
    128.         public Entity userEntity;
    129.  
    130.         public Guid SourceId { get; set; }
    131.         public double ReadyTime { get; set; }
    132.     }
    133. }
    134.  
    However, I am getting the error shown in the title, which is confusing because the Guid creation is being done outside of the Burst-compiled ForEach.