Error Setting Singleton CD

Im having an Error setting a Singleton CD,

// This is the Line throwing the Error, the _singletonSystem is just an Empty system i created just for Singletons

_singletonSystem.SetSingleton(new CameraFocus{Player = players[localPlayerId] });

// Error

InvalidOperationException: SetSingleton<CWBR.Client.Components.CameraFocus>() requires that exactly one CWBR.Client.Components.CameraFocus exists but there are 0.
Unity.Entities.EntityQuery.SetSingleton[T] (T value) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/Iterators/EntityQuery.cs:704)
Unity.Entities.ComponentSystemBase.SetSingleton[T] (T value) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystem.cs:579)
ClientGameManager.InitializeGame (System.UInt16[] pSkins, System.Byte[] teamIds, Unity.Mathematics.float3[] pPositions, System.Byte localPlayerId) (at Assets/Scripts/GameManager/ClientGameManager.cs:206)
ClientGameManager+<Awake>d__15.MoveNext () (at Assets/Scripts/GameManager/ClientGameManager.cs:151)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <437ba245d8404784b9fbab9b439ac908>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <dfc62061cb3f4b1bb57c5179a5db6830>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

You have to first create the entity with the component.

EntityManager.CreateEntity(typeof(CameraFocus));
1 Like

I thought I don’t have to create any entity and the default world already knows which entity need to be used for singletons.

5136674--508334--upload_2019-11-4_16-38-19.png

4 Likes