I have a shader for dissolve effect and end of it need to destroy obj. How can ı assign variable for newly added data component.
My error:
error Assets\Scripts\Systems\DissolveController.cs(33,9): error DC0001: Entities.ForEach Lambda expression uses field 'commandBuffer in a reference type'. Either assign the field to a local outside of the lambda expression and use that instead, or use .WithoutBurst() and .Run()
Here is my code:
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Transforms;
using Unity.Collections;
using UnityEngine;
using Unity.Rendering;
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
public class DissolveController : SystemBase
{
EndSimulationEntityCommandBufferSystem _commandBufferSystem;
public EntityCommandBuffer commandBuffer;
protected override void OnCreate()
{
_commandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
protected override void OnUpdate()
{
float deltaTime = Time.DeltaTime;
commandBuffer = _commandBufferSystem.CreateCommandBuffer();
Entities.ForEach((ref Entity entity,ref DissolveValue dissolveValue, ref DissolveData data) =>
{
if (data.dissolveValue < 1)
{
data.dissolveValue += data.speed;
dissolveValue.Value = data.dissolveValue;
}
else
{
commandBuffer.DestroyEntity(entity);
}
})
.Run();
}
}