First, I generated the AssetBundle using the “Assets>Publish>Content Update” tool. Then I set up HTTP-SERVER on this folder. Then added the ENABLE_CONTENT_DELIVERY micro in PlayerSettings “Scripting Define Symbols”. Finally, the project is packaged into APK. Run it on Android phones, I found that when I created RequestEntityPrefabLoaded, it won’t generate PrefabLoadResult. No objects could be generated in the scene. Why is that?
It’s the code:
using Unity.Burst;
using Unity.Entities;
using Unity.Entities.Serialization;
using Unity.Scenes;
using UnityEngine;
public struct TestPrefabSpawner : IComponentData
{
public EntityPrefabReference prefab;
}
public class TestLoadPrefab : MonoBehaviour
{
public GameObject prefab;
public class Baker : Baker<TestLoadPrefab>
{
public override void Bake(TestLoadPrefab authoring)
{
Entity entity = GetEntity(TransformUsageFlags.None);
#if UNITY_EDITOR
AddComponent(entity, new TestPrefabSpawner()
{
prefab = new EntityPrefabReference(authoring.prefab)
});
#endif
}
}
}
// Provides tag for load callback discrimination
public struct TestTag : IComponentData { }
[BurstCompile]
[RequireMatchingQueriesForUpdate]
public partial struct TestPrefabSystem : ISystem
{
ComponentLookup<PrefabLoadResult> loadResultLookup;
private int frame;
[BurstCompile]
void OnCreate(ref SystemState state)
{
frame = 0;
loadResultLookup = state.GetComponentLookup<PrefabLoadResult>();
state.RequireForUpdate<TestPrefabSpawner>();
}
[BurstCompile]
public partial struct LoadJob : IJobEntity
{
public EntityCommandBuffer ecb;
// Load callback
void Execute(Entity entity, in TestTag tag, in PrefabLoadResult loadResult)
{
Entity inst = ecb.Instantiate(loadResult.PrefabRoot);
ecb.SetName(inst, "TestCube");
Debug.Log("AAAAAAAAAAAAAAAAADD TestCube");
// remove reqeust entity on loaded
ecb.DestroyEntity(entity);
}
}
[BurstCompile]
void OnUpdate(ref SystemState state)
{
loadResultLookup.Update(ref state);
var ecbSingleton = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
EntityCommandBuffer ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged);
// load callback Job
LoadJob job = new LoadJob
{
ecb = ecb
};
job.Schedule();
frame++;
// Create a cubte every 300 frams
if ((frame + 30) % 300 != 0)
{
return;
}
if (!SystemAPI.TryGetSingleton<TestPrefabSpawner>(out TestPrefabSpawner spawner))
{
return;
}
// Start loading, instantiate in the load callback Job
Entity loaderEntity = state.EntityManager.CreateEntity();
state.EntityManager.AddComponentData(loaderEntity, new RequestEntityPrefabLoaded()
{
Prefab = spawner.prefab
});
state.EntityManager.AddComponentData(loaderEntity, new TestTag());
Debug.Log("AAAAAAAAAAAAAAAAADD A CUBE");
}
}
There’s no
“AAAAAAAAAAAAAAAAADD TestCube”
printed at all.
Hello! Have you found out what caused the problem?