Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Entities Invisible with Hybrid Renderer v2

Discussion in 'Graphics for ECS' started by PublicEnumE, Apr 29, 2020.

  1. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    That function has an overload that takes a command buffer.

    That's the point. There's a ridiculous mess of components involved depending which render pipeline you're using, it's not something we should need to be concerned about just to get something to render.

    And yes, there's unfortunately some frustrating undocumented stuff like needing to update renderbounds manually if you change a mesh. Hybrid renderer seems to change a lot between versions, I wouldn't expect super detailed documentation for something like dynamic meshes which is far from the common use case as far as I know. And I say that as someone who does a lot of stuff with dynamic meshes.
     
    deus0 likes this.
  2. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    No doubt most just want a quick out of the box solution for these things while getting the boost of ECS. I know i'm looking forward to 'BatchRendererGroup' seems to be the new goto for custom render solutions. (Graphics class had some limitations)
    But my UI was using the default hybrid, and unlit shaders. But upgrading to v0.11 broke them. But only like sometimes? It was weird. I thought it was broken, I still kinda do.. I'm not sure. But my custom < 100 line render systems had no issues. The only issue is I had to code a bit extra to push the instance data through and add custom shaders.
    I guess ill just keep staying on the old package until I write a render system for it lol but it's weird that it's kinda broken
     
    Last edited: Feb 16, 2021
  3. AznableMiao

    AznableMiao

    Joined:
    Apr 19, 2017
    Posts:
    9
    Same problem, is there any solution?
     
  4. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    333
    The recommended approach is to create one (or more if you need variants) entity in the main thread to act as a "template". Then you can use that with
    EntityCommandBuffer.ParallelWriter.Instantiate
    to create copies of it, and set required values for components using
    SetComponent
    .

    This approach minimizes the amount of structural changes to entities, and the resulting Hybrid Renderer overhead from those structural changes. The approach can be seen in the AddComponentsExample sample in the Hybrid Renderer samples.
     
    deus0 likes this.
  5. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    Is that using a prefab entity? Will a entity archetype do the same job?
    I did convert my spawning to using EntityCommandBuffer.ParallelWriter.Instantiate in parallel systems, however this involves an extra step of sending creating an event component back onto the parent object, and then passing in any uninitialized entities... in order to link them.. This hasn't really caused issues yet though in performance, but perhaps any adding and removing components will causing the main thread to stall? So in general we should do any adding and removing in OnCreate, and the rest of our systems to use use EntityCommandBuffer.ParallelWriter.SetComponent! Reducing any add and remove components that occur. I guess even if its convenient to use set and add, it's better to have prefab entity variations right?

    Also regarding the rendering issues.. not sure how I fixed it, but after updating my unity editor from 2020.1 to 2020.2 it seems to of been fixed.

    Edit: I've posted around, but still stumped. What's the best way to create a camera using pure ECS? Is there a way yet or will there be? (same goes for audio listeners)

    Edit2:
    What is the best way to do events based on the above best practices. Would you recommend adding event components onto entities (AddComponent<ButtonClickEvent>). Or just creating new entities (with ButtonClickEvent) from a prefab entity, and then injecting those into other entities to trigger event functionality, and destroying the even entities after.
    So I am wondering whether EntityCommandBuffer's CreateEntity would be better then AddComponent in terms of events.
     
    Last edited: Mar 14, 2021
  6. AznableMiao

    AznableMiao

    Joined:
    Apr 19, 2017
    Posts:
    9
    I need Instantiate a lot of entities from a prefab entity, should i use entity command buffer or just use EntityManager?
     
  7. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
  8. AznableMiao

    AznableMiao

    Joined:
    Apr 19, 2017
    Posts:
    9
    Yes, i found that and use EntityManager now. But i think that is weird, why entity command buffer can't do this.
    Addtionally, my entities are invisible too and i can't find the reason.
     
    deus0 likes this.
  9. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    I saw in another thread that command buffer should be getting nativearray versions of instantiate in the next release.
     
    deus0 and AznableMiao like this.
  10. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    This is good news, thank you ! :)
    I wonder if it will be more efficient to spawn a list of the entities then spawn one at a time when command buffers get that functionality. Perhaps it is faster due to the way it handles the memory there.
     
  11. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,695
    Did you find a solution to this?
     
  12. OmarVector

    OmarVector

    Joined:
    Apr 18, 2018
    Posts:
    117
    For me, switching to vulkan worked on device
     
  13. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Anyone got a good simple example of how to do this, currently generating entities from a GO Manager as per another example but this is not working vie EntityManager now?
     
    deus0 likes this.
  14. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    I would create the 'spawn lots of things' event from the go manager and add the prefabs to that. Then with the spawn system using ScheduleParallel, pass in the prefab data! Atm I spawn them individually using that Instantiate function.. So really hoping for the batch function later.
    I recommend using the unity ecs documentation for the functions. I'm not sure what code you have as reference, but you just declare the prefab outside the job to pass it in.
     
  15. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    I find this confusing as I thought that once an entity was added to DOTS it would be incorporated within the systems relevant to it *automagically?

    *Well some internal system would ensure new entities were added to the relevant chunks.
     
  16. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    333
    Yes, this API is main thread only. As the example tries to demonstrate, the intended workflow is to construct one entity on the main thread using this API (called "prototype" in the snippet), which you can then instantiate as many times as you want in a parallel job, while also setting the desired component values (such as transforms) using that parallel job.

    AddComponents is a black box by design, so it is possible to change the required components without breaking the users of this API. If you must know what components it adds, you can look at its source code, or you can use the entity debugger to see what components were added (which depends on the settings passed in).