#blob not adding to entity correctly
1 messages · Page 1 of 1 (latest)
oh shoot i must have misread something online
you can expose them in the inspector if you want
using [CreateProperty] on properties within the component
pointing into the blob
OR you can give yourself internal access to entities and write a proper inspector
im trying to use the blob tho in a system and its giving me this massive error every frame NullReferenceException: System.NullReferenceException: The BlobAssetReference is null. This Exception was thrown from a function compiled with Burst, which has limited exception support. 0x00007ffde847028e (Unity) burst_abort 0x00007ffe6494a53e (38bfef227552d435ff94a9ee9b8239d) burst_Abort_Trampoline 0x00007ffe648d3176 (38bfef227552d435ff94a9ee9b8239d) EnemySpawnerSystem.OnUpdate (at C:/Users/cnorw/OneDrive/Documents/GitHub/ECSAssessment/Assets/ECS Scripts/Systems/EnemySpawnerSystem.cs:26) 0x00007ffe648d1080 (38bfef227552d435ff94a9ee9b8239d) 13a12ce769b3aad50874ae63d36c2b60 0x00007ffe779d4b4d (030567238df8ff6ea909a1125c30263) Unity.Entities.WorldUnmanagedImpl.Unity.Entities.UnmanagedUpdate_0000164F$BurstDirectCall.Invoke (at C:/Users/cnorw/OneDrive/Documents/GitHub/ECSAssessment/Library/PackageCache/com.unity.burst@616862665d8c/.Runtime/unknown/unknown:0) 0x00007ffe779d3449 (030567238df8ff6ea909a1125c30263) 7bf3b3dc1c88cb657fd69b548232391d 0x0000020e7f6b48e0 (Mono JIT Code) (wrapper managed-to-native) Unity.Entities.WorldUnmanagedImpl/Unity.Entities.UnmanagedUpdate_0000164F$BurstDirectCall:wrapper_native_indirect_00000210B3C32858 (intptr&,void*) 0x0000020e7f6b4313 (Mono JIT Code) Unity.Entities.WorldUnmanagedImpl/Unity.Entities.UnmanagedUpdate_0000164F$BurstDirectCall:Invoke (void*) 0x0000020e7f6b427b (Mono JIT Code) Unity.Entities.WorldUnmanagedImpl:UnmanagedUpdate (void*) (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/WorldUnmanaged.cs:828) 0x0000020e7f6b3e8b (Mono JIT Code) Unity.Entities.WorldUnmanagedImpl:UpdateSystem (Unity.Entities.SystemHandle) (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/WorldUnmanaged.cs:892) 0x0000020e7f66f8d3 (Mono JIT Code)
its way longer than that but i dont have enough characters
using Unity.Transforms;
[BurstCompile]
public partial struct EnemySpawnerSystem : ISystem
{
int spawnIndicator;
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<EnemySpawnerComponent>();
spawnIndicator = 1;
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
TypeDatabaseComponent typeDatabaseComponent = SystemAPI.GetSingleton<TypeDatabaseComponent>();
ref TypeDatabaseBlob typeDatabase = ref typeDatabaseComponent.TypeDatabase.Value;
foreach (RefRW<EnemySpawnerComponent> spawner in SystemAPI.Query<RefRW<EnemySpawnerComponent>>())
{
BlobAssetReference<WaveBlob> waveBlob = spawner.ValueRO.currentWaveData;
spawner.ValueRW.Timer += SystemAPI.Time.DeltaTime;
if (spawner.ValueRO.Timer < waveBlob.Value.spawns[spawnIndicator].timeSinceLastSpawn)
{
continue;
}
spawnIndicator++;
if(waveBlob.Value.spawns[spawnIndicator].isCluster)
{
}
else
{
spawnIndicator++;
Entity newEnemy = state.EntityManager.Instantiate(spawner.ValueRO.PrefabToSpawn);
LocalTransform newLT = LocalTransform.FromPosition(spawner.ValueRO.SpawnPosition);
TypeBlob enemyType = typeDatabase.Types[waveBlob.Value.spawns[spawnIndicator].spawnId];
ApplyEnemyStats(ref state, ref newEnemy, waveBlob.Value.spawns[spawnIndicator], enemyType);
spawner.ValueRW.Timer = 0f;
}
}
}```
thats the system
i'd check the lenth of spawns first
what line is 26
but it does look like this particular blob might not be setup
im an idiot was using the wrong wave component data ok now it has spawns its not throwing me errors every frame justthis one NullReferenceException: System.NullReferenceException: The BlobAssetReference is null. This Exception was thrown from a function compiled with Burst, which has limited exception support. 0x00007ffde847028e (Unity) burst_abort
so the system isnt finding the blob or it isnt setup
ref TypeDatabaseBlob typeDatabase = ref typeDatabaseComponent.TypeDatabase.Value;```
is this this?
is this being baked?
because subscenes take time to load so won't exist on first frame
it is either that or the wave data
its not being baked but the system gets put on an entity from the on create method ```public partial struct TypeDatabaseSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
TypeSO[] allTypes = Resources.LoadAll<TypeSO>("");
using BlobBuilder builder = new BlobBuilder(Allocator.Temp);
ref TypeDatabaseBlob typeDatabase = ref builder.ConstructRoot<TypeDatabaseBlob>();
BlobBuilderArray<TypeBlob> typesArray = builder.Allocate(ref typeDatabase.Types, allTypes.Length);
for (int i = 0; i < allTypes.Length; i++)
{
typesArray[i] = new TypeBlob
{
id = allTypes[i].id,
health = allTypes[i].health,
speed = allTypes[i].speed,
damage = allTypes[i].damage
};
}
BlobAssetReference<TypeDatabaseBlob> blobAsset = builder.CreateBlobAssetReference<TypeDatabaseBlob>(Allocator.Persistent);
Entity entity = state.EntityManager.CreateEntity();
state.EntityManager.AddComponentData(entity, new TypeDatabaseComponent { TypeDatabase = blobAsset });
}
}```
ok create method would be fine
can you just turn off burst to find exactly the issue?
yeah good idea
Unity.Entities.BlobAssetReferenceData.ThrowIfNull () (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/Blobs.cs:293)
Unity.Entities.BlobAssetReferenceData.ValidateNotNull () (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/Blobs.cs:282)
Unity.Entities.BlobAssetReference`1[T].get_Value () (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/Blobs.cs:448)
EnemySpawnerSystem.OnUpdate (Unity.Entities.SystemState& state) (at Assets/ECS Scripts/Systems/EnemySpawnerSystem.cs:32)
EnemySpawnerSystem.__codegen__OnUpdate (System.IntPtr self, System.IntPtr state) (at <39179709c8314d6db5e874ba81771ba8>:0)
Unity.Entities.SystemBaseRegistry+<>c__DisplayClass9_0.<SelectBurstFn>b__0 (System.IntPtr system, System.IntPtr state) (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/SystemBaseRegistry.cs:249)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/Stubs/Unity/Debug.cs:17)
Unity.Entities.<>c__DisplayClass9_0:<SelectBurstFn>b__0(IntPtr, IntPtr) (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/SystemBaseRegistry.cs:253)
Unity.Entities.UnmanagedUpdate_0000164F$BurstDirectCall:wrapper_native_indirect_000002109E07C2F8(IntPtr&, Void*)
Unity.Entities.UnmanagedUpdate_0000164F$BurstDirectCall:Invoke(Void*)
Unity.Entities.WorldUnmanagedImpl:UnmanagedUpdate(Void*) (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/WorldUnmanaged.cs:825)
Unity.Entities.WorldUnmanagedImpl:UpdateSystem(SystemHandle) (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/Unity.Entities/WorldUnmanaged.cs:891)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@1eebe0437e56/
thats the area with burst turned off
what line is that
{
continue;
}```
pretty sure its that
which means its not reading wave blob correctly
BlobAssetReference<WaveBlob> waveBlob = spawner.ValueRO.currentWaveData;
so this must not be set up correctly#
can you post the waveblob authoring code again
yeah sure
you said something was spawning but still erroring right?
public class WaveBaker : Baker<WaveAuthoring>
{
public override void Bake(WaveAuthoring authoring)
{
Entity entity = GetEntity(TransformUsageFlags.None);
using BlobBuilder builder = new BlobBuilder(Allocator.Temp);
ref WaveBlob waveBlob = ref builder.ConstructRoot<WaveBlob>();
BlobBuilderArray<SpawnDataBlob> spawns = builder.Allocate(ref waveBlob.spawns, authoring.waveData.spawns.Length);
for (int i = 0; i < authoring.waveData.spawns.Length; i++)
{
spawns[i] = new SpawnDataBlob
{
isCluster = authoring.waveData.spawns[i].isCluster,
spawnId = authoring.waveData.spawns[i].spawnId,
timeSinceLastSpawn = authoring.waveData.spawns[i].timeSinceLastSpawn,
populationThresholdTrigger = authoring.waveData.spawns[i].populationThresholdTrigger
};
}
BlobAssetReference<WaveBlob> blobAsset = builder.CreateBlobAssetReference<WaveBlob>(Allocator.Persistent);
AddBlobAsset(ref blobAsset, out _);
AddComponent(entity, new WaveComponent { WaveData = blobAsset });
Debug.Log("baking complete");
}
}```
which seems to imply to me that at least some waveblob has been setup right
but there is somehow an extra waveblob in the world that hasn't been
actually if you go to entity hierarchy
and put in
c=EnemySpawnerComponent
how many are athere?
ill check now
hang on
you posted the code for waveauthoring setting up WaveComponent
foreach (RefRW<EnemySpawnerComponent> spawner in SystemAPI.Query<RefRW<EnemySpawnerComponent>>())
{
BlobAssetReference<WaveBlob> waveBlob = spawner.ValueRO.currentWaveData;
but your job is reading EnemySpawnerComponent
not WaveComponent
yeah so for every enemy spawner in the world i can add the blob to it for reference
apparently none
yea i edited the message
not looking for waveblob
you're looking for EnemySpawnerComponent
but you also haven't posted code where EnemySpawnerComponent is setup
oh sorry ill do that noe
using UnityEngine;
public class EnemySpawnerAuthoring : MonoBehaviour
{
public GameObject PrefabToSpawn;
public float SpawnDelay;
private class EnemySpawnerBaker : Baker<EnemySpawnerAuthoring>
{
public override void Bake(EnemySpawnerAuthoring authoring)
{
Entity e = GetEntity(TransformUsageFlags.None);
AddComponent(e, new EnemySpawnerComponent
{
PrefabToSpawn = GetEntity(authoring.PrefabToSpawn, TransformUsageFlags.Dynamic),
Timer = 0.0f,
SpawnDelay = authoring.SpawnDelay,
SpawnPosition = authoring.transform.position
});
}
}
}```
so where is currentWaveData being setup
in that baker?
you just don't seem to have assigned the blob at all
or am i missing something
its setup as a scriptable object called WaveSO which is assigned in the wave authoring ```using UnityEngine;
public class WaveAuthoring : MonoBehaviour
{
public WaveSO waveData;
}```
and then im trying to turn that to a blob in wave baker
foreach (RefRW<EnemySpawnerComponent> spawner in SystemAPI.Query<RefRW<EnemySpawnerComponent>>())
{
BlobAssetReference<WaveBlob> waveBlob = spawner.ValueRO.currentWaveData;
if (spawner.ValueRO.Timer < waveBlob.Value.spawns[spawnIndicator].timeSinceLastSpawn)
you're reading
EnemySpawnerComponent.currentWaveData
but no where in your EnemySpawnerAuthoring is this being set?
so where is it being set
using Unity.Mathematics;
public struct EnemySpawnerComponent : IComponentData
{
public Entity PrefabToSpawn;
public float Timer;
public float SpawnDelay;
public float3 SpawnPosition;
public BlobAssetReference<WaveBlob> currentWaveData;
}```
its declared on the component then im trying to set up where you just showed
but you're reading from it
if (spawner.ValueRO.Timer < waveBlob.Value.spawns[spawnIndicator].timeSinceLastSpawn)
before you create it
waveBlob.Value
is not created
as the error says
i thought bake happened before compile time?
but you haven't baked it
where is it baked
the code you have posted has not baked this
AddComponent(e, new EnemySpawnerComponent
{
PrefabToSpawn = GetEntity(authoring.PrefabToSpawn, TransformUsageFlags.Dynamic),
Timer = 0.0f,
SpawnDelay = authoring.SpawnDelay,
SpawnPosition = authoring.transform.position,
currentWaveData = null, // <---------------------- this is what you're saying
});```
you have not written this value