Hi, im trying to instantiate a bunch of entities and move them at runtime. They are currently instantiated but the RenderMeshSystemV2 takes too long.
Someone know how to reduce this time?I leave the code that I use to instantiate here below
if (spawnBallsAuto)
{
//for (int i = 0; i < 10; i++)
//{
objfps = GameObject.FindGameObjectWithTag("FPSCount");
objfps.GetComponent<BallsCount>().balls += 1;
//obtenemos los ghost
var ghostCollection1 = GetSingleton<GhostPrefabCollectionComponent>();
//obtenemos el id del ghost que nos interesa
var ghostId1 = ProyectoNetcodeGhostSerializerCollection.FindGhostType<PelotaSnapshotData>();
//su prefab
var prefab1 = EntityManager.GetBuffer<GhostPrefabBuffer>(ghostCollection1.serverPrefabs)[ghostId1].Value;
//y lo instanciamos
var pelota = EntityManager.Instantiate(prefab1);
float xa = UnityEngine.Random.Range(-10, 10);
float ya = 2.5f;
float za = UnityEngine.Random.Range(-10, 10);
//le añadimos el componente de posicion
EntityManager.SetComponentData(pelota, new Unity.Transforms.Translation { Value = new float3(xa, ya, za) });
}
And the code to move the entities
public class MovePelotaSystem : JobComponentSystem
{
protected override void OnCreate()
{
RequireSingletonForUpdate<EnableProyectoNetcodeGhostSendSystemComponent>();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
return Entities.WithAll<PredictedGhostComponent>().ForEach((ref Translation trans,ref PelotaComponent pelota) =>
{
if (trans.Value.y >= 9)
trans.Value.y = 2.5f;
else
trans.Value.y += 0.03f;
}).Schedule(inputDeps);
}
}