I am taking in a NativeArray of PlayerScore components to a .ForEach using .Run() which should update the PlayerScores based on the results of Unity Physics collisions.
Component Data:
[GenerateAuthoringComponent]
public struct PlayerScore : IComponentData
{
// [GhostField]
public int networkId;
[GhostField]
public FixedString64 playerName;
[GhostField]
public int currentScore;
[GhostField]
public int highScore;
}
Passing the data into the .ForEach:
var playerScores = m_PlayerScores.ToComponentDataArrayAsync<PlayerScore>(Allocator.TempJob, out playerScoreDep);
The .ForEach:
Entities
.WithName("ChangeMaterialOnTriggerEnter")
.WithoutBurst()
.ForEach((Entity e, ref DynamicBuffer<StatefulTriggerEvent> triggerEventBuffer, ref TriggerChangeMaterialAddDestroyTag changeMaterial) =>
...
Dependency = JobHandle.CombineDependencies(m_TriggerSystem.OutDependency, Dependency, playerScoreDep);
m_CommandBufferSystem.AddJobHandleForProducer(Dependency);
playerScores.Dispose();
For some reason as I run:
for (int j = 0; j < playerScores.Length; j++)
{
Debug.Log("playerScores[j].networkId " + playerScores[j].networkId);
}
It returns: 654685472
or some other random large number. In the entity debugger the PlayerScore entity clearly has networkId value of 1.
Why are these random numbers showing up? It seems like I am access unmanaged memory and it is returning a random value but I think I am providing the data as I should?
If I change to:
var playerScores = m_PlayerScores.ToComponentDataArray<PlayerScore>(Allocator.TempJob);
``` it works fine and I receive the expected data.