#(Doofus) Using entity queries from ScriptableRenderPass breaks all other queries in monobehaviours.

1 messages · Page 1 of 1 (latest)

lavish epoch
#

Edit: There is a bug where there is no error message. Something to do with calling a query from the render thread messing stuff up.

Heya,

I need to access singleton data from a scriptablerenderpass for some rendering stuff, I've noticed that whenever I use a query in that context, all of my other queries break in monobehaviours completely break down. Not as in I'm getting errors, but as in all the data is literally empty. The components themselves are fine, just whenever I query for them in monobehaviours, I'm receiving null (well, the struct equivalent of null, which I suppose is just default).

Before I submit a bug report, I want to check if what I'm doing is even possible. Maybe the bug here is that I'm not getting an error message saying I can't query from the render graph.

#

Actually it's not all queries

#

only a query to get an unrelated singleton component on a different entitiy

kind kestrel
#

(there's a reason i've been repeating for years not to access ecs data from outside the world)
how are you ensuring dependency/safety?

#

are you completing the query dependency before accessing it

lavish epoch
#

💀

kind kestrel
#

of course, entity query has, CompleteDependency on it as a method

#

dependencies are only really handled for you between systems, or when using entitymanager
outside of that, it's basically your responsibility

lavish epoch
#

(Doofus) Using entity queries from ScriptableRenderPass breaks all other queries in monobehaviours.

kind kestrel
#

now i'm surprised you aren't getting errors if you are doing something wrong and it's breaking

#

because that is raising flags

#

do you know if ScriptableRenderPass happens on main thread?

#

or is it done in a separate graphics thread

#

because if it's in a separate thread, there's no real way to do this safely

lavish epoch
lavish epoch
kind kestrel
lavish epoch
kind kestrel
#

when i say mono world, i just meant monoebaviours etc

#

not an actual 'world'

lavish epoch
#

Ahk

kind kestrel
#

have a system write to graphics buffer that the ScriptableRenderPass can read from for example

lavish epoch
# kind kestrel but yes exactly this

I tried doing that once, but I'm not sure how I would exactly get a reference from authoring to my system without using either managed components or Gameobject.find

kind kestrel
#

i have a ScriptableRenderPass for my draw system

#

the system sets it up in oncreate

#
#if UNITY_URP
            RenderPipelineManager.beginCameraRendering += this.BeginCameraRendering;
#endif
        }

#if UNITY_URP
        private void BeginCameraRendering(ScriptableRenderContext context, Camera camera)
        {
            var data = camera.GetUniversalAdditionalCameraData();
            if (data != null)
            {
                if (this.renderPass == null)
                {
                    this.renderPass = ScriptableObject.CreateInstance<DrawURPRenderPassFeature>();
                    this.renderPass.SetSystem(this);
                }

                this.renderPass.AddRenderPasses(data.scriptableRenderer);
            }
        }
#endif

is my setup for example

lavish epoch
#

not just for the graphics but in general, for something like UI, I need a reference to UI to change text on it or something

kind kestrel
#

well i have a whole framework for UI that lets me write to UI from bursted ISystem

lavish epoch
#

lmao

kind kestrel
#

but there's nothing wrong with just having a UIManager singleton or something

#

a system can access

#

you don't need to go my extremes

#

if you do want to access ecs world from monobehaviours, just use entitymanager

#

if you need queries, just complete dependency before using them

#

(create them from EM, make sure you remember to dispose them. EntityQuery needs to be disposed if it's not created from a system [which auto disposes it for you])

#

i still prefer not to access entity world from monobehaviour, but if you do, do it that way

#
  • use EM where possible, it handles dependency completion for you
  • or complete query dependencies yourself (entityQuery.CompleteDependency)
lavish epoch
#

Already using entity manager for queries 😎

lavish epoch
kind kestrel
#

I got no leak messages for creating those queries, this is massive news to me lol. Ig I gotta do that too now.
they won't 'leak' because when you shut down the world it does clean them up

#

but they hang around until the world is disposed

#

so if you just keep calling CreateEntityQuery for short term lived stuff or dynamically, they'll just keep building up

kind kestrel
lavish epoch
#

I think some pointer is incorrect and pointing to empty data and that is just not being detected somehow

#

because I'm "recieving" that singleton data

#

it's just empty

#

but even, an incorrect pointer would have random ass data, not being completely empty

lavish epoch
#

I'll just overengineer my own mono query system

kind kestrel
#

i should say, em does cache queries so it shouldn't be an issue most of the time