I made a jam game with DOTS + DOTS physics, here's my thoughts on the current API

I just participated in Ludum Dare 46 and decided to use it as an excuse to look into using DOTS physics so I made this game with thousands of scripted rigidbodies. I don’t think I could have made this game concept with PhysX.

5743954--603607--GameplaySmallSize.gif

I’ve been using DOTS for a while now in my own game so it’s been interesting following how the API has changed. I thought I’d write down my thoughts and findings on working with Entities 0.9.1 and my initial experience with DOTS physics 0.3.2 maybe it will be of use to others.

Stuff I like

  • The game object to entity conversion workflow is getting very good. I was impressed it can handle lights now

  • Using lambda expressions for parallel code works really well

  • The [GenerateAuthoringComponent] system is very handy

  • You can declare an Entity in an IComponentData and the authoring system will expose it as a GameObject field in the editor, neat!

  • Authoring objects in the scene for physics worked really well.

  • GameObject hierarchies can be converted into entity hierarchies without issue

Stuff I don’t like

  • I still don’t like systems auto start. In my case I had all the ECS samples and Physics samples in my project for reference and my Entity debugger was cluttered up with their systems. I’m also worried that systems could run in scenes where you don’t want them to run.

  • Not having access to PostUpdateCommands in SystemBase leads to a lot of boilerplate code.

  • Using Entities.WithName(“Player”) in SystemBase seems to return all entities

  • Reloading the scene doesn’t destroy existing entities. I was expecting that to be the default behaviour

  • I still can’t figure out a clean pattern to provide non entity data to systems. I can see you sometimes uses an entity to pass in data but lets say I’ve used an AnimationCurve to define spawn rate for an enemy that wouldn’t work in an IComponentData

  • It would be nice if there was an easy way for jobified code to queue up method calls on the main thread once it’s done say EntityCommandBuffer.Concurrent.MainThreadAction(Action<> action). Would be super useful to allow ECS code to make use of the existing code base. Not sure how this is going to play with Burst but it would be handy to have. Otherwise an example on how to say play an AudioSource or instantiate a shuriken particle effect when an impact occurs would be helpful.

Random questions I had during the weekend

  • How do you iterate through an entity hierarchy? Not sure if there is an example for that
  • Does skinned mesh renderers work with DOTS? I had a model that used it and it didn’t seem to work with the conversion system
7 Likes

Look into blob data :slight_smile: it’s immutable and will be passed around by reference, and you can store it (a pointer to it) on components.

1 Like

Awesome game! Awesome feedback. A couple of tips based on the things you don’t like or had questions on:

  1. Systems auto start
    Initializing all systems to exist independent of scene or state at the start of the game is an ECS paradigm that results in lots of pain and suffering if you don’t follow. The problem comes from when Unity auto-injects systems using magical attributes and attempts to do system execution filtering magically for you rather than give you control. Fortunately, the former problem can be solved with ICustomBootstrap. And the latter problem can be solved with some abstract subclasses.
  2. PostUpdateCommands
    Totally agree. Though I don’t trust Unity to choose my sync points for me. I believe this is also a problem that can be solved with some abstract subclasses, though I haven’t gotten around to it yet.
  3. WithName
    WithName names the code-generated Entities.ForEach job for errors and debugging purposes. It has nothing to do with entity filtering. I agree it is confusing.
  4. Scenes
    Entities are not tied to scenes. You have to do that yourself (it is pretty easy). On the bright-side, this offers you a means to stash the contents of a scene into a different world so that when you return back to a scene it keeps all modifications.
  5. Non-entity data
    For immutable data, Blobs are the answer. For mutable data, you still want to tie things to “GameManager” or “Profile” entities.
  6. You have to use your own event mechanism for some of these things. If the main thread activity lasts for more than one frame, instantiating an entity with a unique component type and having a system iterate over all those entities is a great approach. For one-time events, writing into a NativeContainer is typically faster.
  7. Hierarchy iteration
    You can look at ParentSystem.cs to see how they do it.
  8. There’s an animation system package for DOTS, but it is hidden from the package manager so you have to add it to your manifest directly.
5 Likes

Thanks for the replies both of you I need to look into Blobs and managing my own Worlds. I think some examples that are actual full game loops with VFX, SFX and GUI from Unity’s side would be handy to showcase the best practices on how to use the API but I’m sure that’s on the roadmap once it’s more finalized.

3 Likes

Nice game. Great to see this kind of feedbacks!

You can see examples of that in the Animation package here

2 Likes

This has been the biggest problem I face till now, there should be some user-friendly way to manage it, currently I have extra component Tags for the systems I want them to act on. But tI don’t wanna create a new tag for every new system I create

1 Like

What would you rather do instead?

I ask because I may have already written the solution you are after.

1 Like

I could have some kind of per world configuration file that could authored in editor but could be modified by scripts as well for small and easy projects, where I don’t need to create a ICustomBootstrap for each configuration and scene that I need

As this point could be a major source of bugs in games, so it would be pretty useful if they could make it much easier than it is right now to define the systems running in a given world, and not make having new bootstrap scripts the only way to define the behaviour as it really slows down iteration speeds and subsequently our creativity

This isn’t quite what you want, but maybe it helps?

1 Like

Just going through your physics Code I really have no idea why unity isn’t using Entity query when it’s fast as hell for all practical reasons, also this one particular thing has been one of the most painful things about physics till now which is the layer system, I understood why it’s needed in older unity considering object-oriented nature and random access all over the place with components but why in the world couldn’t they have done something with new tag-based system, even with the random access required it would still be fast enough IMO. This would just be much more liberating than what we have today in form of a layers system, which is constrained to just 8 or 32 layers if I remember correctly.

The second point you mention about the collider mesh being a blob asset, it really shows unity is targeting specific use cases for physics rather being more generic as they should be.

You should really make a post about this in DOTS physics section about this

1 Like

Did I link the wrong documentation page? :stuck_out_tongue:

I warned them about the fundamental design flaws and how they were going to cause usability issues way back when it first released two years ago. They acknowledged my post but didn’t seem to take my warnings seriously. Don’t get me wrong. They are extremely nice and friendly people! :sunglasses: And the tech works great if it meets your use case and you can stomach the non-DoD (albeit still Burst-friendly) API. But I’ve long since given up arguing. You are welcome to bring it up in that subforum though.

I have a video I am trying to finish up, and a game jam in 8 days. But after that, I’ll be back to developing new features and Psyshock will be my main focus. If you have any feedback, questions, or criticism, by all means feel free to ping me about it public or private! :slight_smile:

1 Like