EDIT: The resolution was that Entities cannot be seen moving in Scene View, but they are visible in Game View.
Edit #2: If you go to the menu EDIT > PREFRENCES. Then select the ENTITIES option, there is a section called “Baking”, the option “Scene View Baking” Set this to “Runtime Data” to see entities move in Scene View. (Thanks to @Rukhanka for this info)
I was following along with Code Monkey’s latest ECS tutorial and while most everything with it is fine, Unity dropped TransformAspect. Some reading shows that the LocalTransform is the replacement that I need to affect.
So I update my code as follows, but the thing is, within the Inspector I can watch as the Local and Local To World values update, however the visual object (sphere, sprite, whatever) does not move.
I’m happy to post my code if anyone wants that, but since I can see the values for any of these entities are updating when I select that specific one within the Entities Hierarchy. So it feels like a render or some other dumbass thing I am doing wrong.
Could be lots of things. One thing that happened to me two days ago, was that the Entities.Physics package was somehow decoupling child objects from the parents. Everything worked before installing it, but after getting it I had to restructure a bit.
But it is probably something simpler, could you maybe share a screenshot of your hierarchy and the inspector of the gameobject that should move? If there are any scripts attached to that gameobject, especially a baker, might help to see them, too.
You can see by the red outline the start position and it’s Target Position (Baker value) At runtime you can see the LocalTransform’s position updated (also shown highlighted)
Here is the basic code, a struct that moves items from one place to another. Simple… and yet…
At this point I’m getting more and more sure it’s something REALLY dumb that I am doing. (feel free to point and laugh)
public partial struct BattleBotMovementSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
float deltaTime = SystemAPI.Time.DeltaTime;
JobHandle jobHandle = new BattleBotMoveJob
{
deltaTime = deltaTime
}
.ScheduleParallel();
jobHandle.Complete();
}
}
public partial struct BattleBotMoveJob : IJobEntity
{
public float deltaTime;
public void Execute(MoveToPositionAspect moveToPositionAspect)
{
moveToPositionAspect.Move(deltaTime);
}
}
--------------------
public readonly partial struct MoveToPositionAspect : IAspect
{
private readonly RefRW<LocalTransform> localTransform;
private readonly RefRO<Speed> speed;
private readonly RefRW<TargetPosition> targetPosition;
public void Move(float deltaTime)
{
float3 direction = math.normalize(targetPosition.ValueRO.value - localTransform.ValueRO.Position);
localTransform.ValueRW.Position += direction * deltaTime * speed.ValueRO.value;
//localTransform.ValueRW.Position = new float3(0, 0, 0); //yes, the values get set, but the visual does not move
}
Mhh, I don’t see anything obvious. Three things come to mind though.
First, which version of the Entities package are you on? Mine doesn’t seem to have a ScheduleParallel() Version without arguments that returns a JobHandle. Does not seem to be in the documentation either. I had problems with jobHandle.Complete() in the past, could you try running it without the jobHandle just like:
new BattleBotMoveJob
{
deltaTime = deltaTime
}.ScheduleParallel();
Second, could you share the bakers maybe, the three files on your battle-bot?
When I updated the code as you stated above, but with .Run I get the following error. I do not get it when running Schedule or ScheduleParallel
I do have a handful of Warnings and the only one that makes me wonder is this vague one:
Internal: JobTempAlloc has allocations that are more than the maximum lifespan of 4 frames old - this is not allowed and likely a leak
To Debug, run app with -diag-job-temp-memory-leak-validation cmd line argument. This will output the callstacks of the leaked allocations.
I’m gonna stop for the night. Maybe something will come to me.
I also wanted to thank you again for your time
InvalidOperationException: The previously scheduled job LocalToWorldSystem:ComputeChildLocalToWorldJob reads from the ComponentTypeHandle<Unity.Transforms.LocalTransform> ComputeChildLocalToWorldJob.JobData.LocalTransformLookupRO. You are trying to schedule a new job BattleBotMoveJob, which writes to the same ComponentTypeHandle<Unity.Transforms.LocalTransform> (via BattleBotMoveJob.JobData.__TypeHandle.__MoveToPositionAspect_RW_AspectTypeHandle.MoveToPositionAspect_localTransformCAc). To guarantee safety, you must include LocalToWorldSystem:ComputeChildLocalToWorldJob as a dependency of the newly scheduled job.
Unity.Jobs.LowLevel.Unsafe.JobsUtility.Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters) (at <6c9b376c3fca40b787e8c1a2133bf243>:0)
Unity.Entities.JobChunkExtensions.ScheduleInternal[T] (T& jobData, Unity.Entities.EntityQuery query, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode, Unity.Collections.NativeArray`1[T] chunkBaseEntityIndices) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/IJobChunk.cs:322)
Unity.Entities.JobChunkExtensions.RunByRef[T] (T& jobData, Unity.Entities.EntityQuery query) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/IJobChunk.cs:229)
BattleBotMoveJob+InternalCompilerQueryAndHandleData.Run (BattleBotMoveJob& job, Unity.Entities.EntityQuery query) (at Unity.Entities.SourceGen.JobEntityGenerator/Unity.Entities.SourceGen.JobEntity.JobEntityGenerator/Temp/GeneratedCode/Assembly-CSharp/BattleBotMovementSystem__JobEntity_6923671380.g.cs:170)
BattleBotMovementSystem.__ScheduleViaJobChunkExtension_0 (BattleBotMoveJob job, Unity.Entities.EntityQuery query, Unity.Jobs.JobHandle dependency, Unity.Entities.SystemState& state, System.Boolean hasUserDefinedQuery) (at Assets/HBC/Scripts/ECS/BattleBotMovementSystem.cs:45)
BattleBotMovementSystem.OnUpdate (Unity.Entities.SystemState& state) (at Assets/HBC/Scripts/ECS/BattleBotMovementSystem.cs:13)
BattleBotMovementSystem.__codegen__OnUpdate (System.IntPtr self, System.IntPtr state) (at :0)
Unity.Entities.SystemBaseRegistry.ForwardToManaged (System.IntPtr delegateIntPtr, Unity.Entities.SystemState* systemState, System.Void* systemPointer) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/SystemBaseRegistry.cs:371)
Unity.Entities.SystemBaseRegistry.CallForwardingFunction (Unity.Entities.SystemState* systemState, Unity.Entities.UnmanagedSystemFunctionType functionType) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/SystemBaseRegistry.cs:340)
Unity.Entities.SystemBaseRegistry.CallOnUpdate (Unity.Entities.SystemState* systemState) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/SystemBaseRegistry.cs:383)
Unity.Entities.WorldUnmanagedImpl.UnmanagedUpdate$BurstManaged (System.Void* pSystemState) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/WorldUnmanaged.cs:855)
Unity.Entities.WorldUnmanagedImpl+UnmanagedUpdate_0000153F$BurstDirectCall.Invoke (System.Void* pSystemState) (at :0)
Unity.Entities.WorldUnmanagedImpl.UnmanagedUpdate (System.Void* pSystemState) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/WorldUnmanaged.cs:828)
Unity.Entities.WorldUnmanagedImpl.UpdateSystem (Unity.Entities.SystemHandle sh) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/WorldUnmanaged.cs:913)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/ComponentSystemGroup.cs:729)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/ComponentSystemGroup.cs:740)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/ComponentSystemGroup.cs:693)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/SystemBase.cs:418)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at ./Library/PackageCache/com.unity.entities@1.0.10/Unity.Entities/ScriptBehaviourUpdateOrder.cs:526)