#Accessing ECB singletons from MonoBehaviour?

1 messages · Page 1 of 1 (latest)

indigo flume
#

I want to access one of those singleton ECBs (BeginInitialisationECB) from a MonoBehaviour to not create a sync point when setting my UI input data. What exactly am I looking for? BeginInitializationEntityCommandBufferSystem appears to be some sort of ComponentSystemBase but how do I access the command buffer from there?

spare lava
#

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

indigo flume
spare lava
#

just make sure you don't use CreateCommandBuffer from a callback on another thread, you will get no safety warning you corrupting the system

indigo flume
#

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)

spare lava
#

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>

spare lava
indigo flume
# spare lava you just need World.GetExistingSystemManaged<BeginInitializationEntityCommandBuf...

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