#Accessing ECB singletons from MonoBehaviour?
1 messages · Page 1 of 1 (latest)
While I always strongly recommend against ever accessing entities world from gameobjects, if you insist there's just a method on the command buffer system called CreateCommandBuffer
you need nothing else
this is basically the old (0.51 and earlier) way of using ecbs
Ik I should be accessing UI stuff from a system base instead of a monobehaviour but I really can't be bothered getting all my buttons and shit into a system base. I tried using a managed component to hold references but they cant hold references to stuff outside of their world, so I just gave up.
just make sure you don't use CreateCommandBuffer from a callback on another thread, you will get no safety warning you corrupting the system
Also how can I get a reference to the singleton system? is it GetExistingSystemManaged? Also I'm using generics if that plays a role.. Here's what I have so far:
public static T1 GetSingleton<T1>() where T1 : unmanaged => DefualtWorld.GetExistingSystemManaged(typeof(T1));
I took a look at the SystemAPI.GetSingleton but it doesn't help at all,
public static T GetSingleton<T>()
where T : unmanaged, IComponentData => throw Internal.InternalCompilerInterface.ThrowCodeGenException();
Open source my ass
(Realistcally the code is somewhere else because it uses codegen)
you dont need access to the singleton
you just need access to the system
the singleton is used to add dependencies for systems for jobs to be completed before the playback
you just need World.GetExistingSystemManaged<BeginInitializationEntityCommandBufferSystem>
^
there's just a method on the command buffer system called CreateCommandBuffer
Oh nice, I can't seem to use generics with it though, is there something I'm missing or are there just no generics allowed?
public static T1 GetSingletonSystem<T1>() => DefualtWorld.GetExistingSystemManaged<T1>();
yeilds the error:
The type 'T1' cannot be used as type parameter 'T' in the generic type or method 'World.GetExistingSystemManaged<T>()'. There is no boxing conversion or type parameter conversion from 'T1' to 'Unity.Entities.ComponentSystemBase'
nvm I fixed it