Jump to content

Visual Pinball in Unity, 2024

Recommended Posts

Hi folks!


2023 was a bit of a slow year for VPE. I'll go into more details in a minute, but in general, side-project fatigue happens, and in order not to burn out, taking things slowly for a while is necessary. I've also changed jobs, so naturally, I'm a little bit more invested in my professional life.


That's not to say I'm distancing myself from the project; on the contrary. There's lots of cool stuff to be done, and working with a supporting community motivates a lot. It's a genuine pleasure to share ideas and progress with you guys, discuss potential features and limitations of the engine, or post random stuff I've been working on, like this spinner.



So, let's have a look at 2023.


DOTS v1.0 came out at the end of 2022, and quite a few things changed. A quick primer about DOTS: It's Unity's ECS implementation, meaning instead of the classic object-oriented approach, data is packed in a way that is much more accessible by the CPU, avoiding cache misses. Together with Unity's Jobs system and Burst, it offers an insane amount of performance if you're dealing with many objects (tens of thousands).


VPE's physics port from VPX was based on DOTS, and with v1.0 coming out, much refactoring was ahead, since v1.0 broke most of the APIs of the previous beta versions. I started this in January, but there were a few things that had changed significantly:


  1. DOTS worlds must be contained in a sub-scene, i.e., a different file. This sounded great at first (it would be easier to integrate sub-scenes / tables into existing rooms/surroundings), but it didn't play well because we didn't use the DOTS renderer: Nothing was rendered on screen during runtime.
  2. Conversion is now taking place at build time through bakers. This is a problem because we want to load tables during runtime and need another way to bake.


It's probably possible to work around those issues, but I had a hunch since I started with DOTS: Since every system (the code that simulates the physics world) is launched from the main thread, a lot of scheduling is going on. Every piece of logic (there were around forty systems) needs to be scheduled, even if not executed, on a different thread, for every tick of the physics simulation. This overhead is okay when dealing with thousands of objects that can be distributed over multiple cores, but here, we can't really do that, and even if we could, we would probably parallelize the ball simulation, and there aren't as many balls. Thus, removing DOTS might result in actually better performance.


So, I started rewriting the physics without DOTS. To at least keep the current performance, all data should be tightly aligned in memory, and there should be no managed allocations, which would make the garbage collector kick in (and introduce frame drops).


I somewhat finished refactoring all of this at the end of February, but then DMDext became more urgent, and I switched projects. It still didn't work, though. I only refactored it for two collider types, and one of them didn't work at all. I did some fixes in March, but DMDext consumed most of my free time until the end of August.


In September, I slowly started to pick it up again, but there were still a lot of bugs, and physics in general are a nightmare to debug (imagine debugging through data at 1000 fps), so progress was tough.


Then came the Unity debacle. Basically, Unity was demanding an "install fee" retroactively from the studios using the engine. Although this was a tremendously stupid idea (how would you track "installations"?), breaking users' trust by changing the rules retroactively was the main reason the whole game industry was in an uproar. It ended with Unity's CEO stepping down and most of the new terms being rolled back, but like many other Unity developers, it made me spend over a week looking at Godot and rethinking my life choices. ;)


I won't get into too much detail, but the main reason I finally decided to continue VPE in Unity was simple: I really like working with it, and it's still the best tool for the job, even compared to UE5.


But back to DOTS. At the beginning of October, I finally got it running again with just Burst and Jobs. Here's a scene with 60k colliders:



Using DOTS, this takes about 12ms per frame to simulate. After the refactoring, we got this:



That's 0.2ms per frame for the entire physics simulation! That's a 60x boost of performance, which is crazy.


This immediately raises the question: Why don't we make the colliders dynamic? You move, scale, or rotate an object during gameplay, and the physics simulation updates accordingly. That's something VPX can't do.


So, let me introduce kinematic objects. You can now tick a checkbox, and objects marked as kinematic will do that. One catch, though: Kinematic objects don't have a velocity. So, if your object moves and collides with a ball during movement, its velocity isn't applied. It's like the object teleports, frame by frame, to its new position. I'll address this soon, but for now, it still offers a massive benefit for features like diverters, whose movement is less important than having them on multiple positions without manually creating numerous objects and toggling them, as we have to do in VPX.


For example, here I'm transforming a ramp, live during gameplay, and the physics update in real-time.



The present


While discussing these changes on Discord, a strongly related topic emerged: Freedom of how objects can be transformed. See, modern game engines build their 3D scenes through a hierarchy. That means you can parent objects; if you transform the parent, its children are transformed along. This is essential for many use cases. Imagine a player character holding an object. You don't want to have to transform the object and the character separately when your character moves in your scene. You parent the object to the character and let the engine do the rest.


Unity is also built like this, but because our physics engine doesn't support full transformations, we had to add many hacks to the editor to not let the user transform all objects freely. For example, VPX's physics doesn't support flippers rotating on any axis other than the Z axis. Or, walls cannot be rotated at all. Not being able to transform freely also restricted parenting. While we can somewhat control how an object can be transformed, applying those constraints to its parent is difficult, especially if there are siblings with different constraints.


Long story short, having complete freedom regarding transformation would solve many problems. So, I'm currently working on adding this to the physics engine.


Here's an example of a flipper rotated to match a different playfield slope, something currently not possible in VPX:



The future


As mentioned above, kinematic colliders don't have velocities, so they can only be used for a few use cases. The next logical step is adding support for this to the physics engine and a set of components that can be linked to ROM outputs. We'll probably call those dynamic colliders.


After that, the goal is to get the first SS game fully working. T2 is a good candidate, but we've since started a few other projects, so it might be a different table.


In general, two major features still need to be implemented: A player app to load and play tables and an export format that can be loaded by the player app and allows importing a table back into the editor. Let me know if anyone with a C# or Unity background feels like tackling this!

That's it for now


I hope that every one of you is having a peaceful holiday. Personally, I'm excited about what's to come. If you're a developer and you are too, and you've got some time to help, let me know!


Happy New Year, everybody!



Link to comment
Share on other sites

Thanks Freezy (and team) for all your hard work on VPE and all the other work you do for this community.

All the stuff you showed in the past and in this thread looks really awesome.  So I'm really thrilled for what the tables will be bring for us (on cabinet and VR as well ?)


I hope 2024 will be a legendary year for VPE.

Best wishes and a happy new year !

Edited by MikeDASpike
Link to comment
Share on other sites

A fascinating read Freezy - many thanks for the developers diary.


The refactoring and reworking you had to do clearly sounds like it was a huge amount of work and must have caused a few headaches.  It must however be so good to know that code is now organised/reworked in a better structure/shape to support the development going forward (eg: Physics separation from DOTS, etc.).  The 60x performance boost must have been so satisfying! 😁 Congratulations on that achievement btw 🤝


The new developments are also super impressive.  Love the mechanism on the spinner - the level of detail is unbelievable!   The kinematic objects sound awesome too - I will read up some more on those.


Thanks again for the updates and hope you are enjoying your new professional role.  Cheers 👍

Edited by jupiter
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

Not from me, i've got mail notifications from github about discussions about VPE between You and others members and some guy send You a question about VPE and You obviously not responded to that mail cause i didn't have notification from github about Your answer to that guy.

Link to comment
Share on other sites

1 hour ago, Dariusz75 said:

There is no need to be upset, besides, last update was in December and we now have almost half of the March.

You know, good developers, you gotta let 'em talk if they want. But if they're hiding and you don't hear from them for months, that's when you know they're making the best progress on their projects!

Link to comment
Share on other sites

Last updated file on github was over 2 months ago. 

I'm following this thread from the beginning and with each new year work is getting slower and slower.


Edited by Dariusz75
Link to comment
Share on other sites

  • Content Provider
15 hours ago, Dariusz75 said:

Last updated file on github was over 2 months ago. 

I'm following this thread from the beginning and with each new year work is getting slower and slower.


** extreme eye roll **

Link to comment
Share on other sites

On 3/10/2024 at 7:12 AM, Dariusz75 said:

Last updated file on github was over 2 months ago. 

I'm following this thread from the beginning and with each new year work is getting slower and slower.



I rarely comment on things but I couldn't resist in this case.  I am so curious as to what your post was intending to do.  Is the end goal to motivate and inspire freezy to work faster?  Is it to make it known to the rest of the VP community just how passionate and excited you are about the future?  If so, then I'm afraid you missed your mark by quite a bit.  If not, then what were you hoping to get across?   I don't want to offend if English is a not your first language, but I thought you should know that I think (and confirmed by seeing @apophis's reply) that your post comes across as ignorant to the actual complexities of what he is trying to create (at best), and entitled/ungrateful (at worst)


Aren't you thankful for freezy and all the other community creators who spend their free time creating the content you love and use for free?  Of course you are!  So if you MUST comment in this thread, why not say that instead?  Don't you think that is more motivational for freezy (which will help VPE be ready sooner - your goal?) than a generic statement about the "lack" of progress?  This is especially true when he literally provided a comprehensive progress update and stated how much of a motivator a supportive community is to him.


As an aside...it feels like whenever freezy graciously provides a detailed update on VPE progress (which he does not have to do), the "supportive" community members eventually come around to express how frustrated they are that this free tool that will provide them so much joy for free is taking so long.  I had to say something.  I'm not a developer and won't pretend to know what it would be like to spend so much of my spare time creating such an incredibly complex and complicated tool that will completely change our hobby and take it to the next level, only to have the same people I'm devoting so much time and energy to, act entitled and/or ungrateful.  Since I do not have the skills to contribute to VPE, I also waive my right to complain and feel like someone owes me something.  It will be ready whenever he deems it ready....or not.  Whatever he decides since he owes us nothing.  IMHO....if you are not a contributor to the project then we should sit down, shut up, and be thankful this is even a thing!


Freezy clearly has seen it all before and has shown that he has way more patience than most.  Thank you @freezy for your contributions to this and other open source projects (XBMC forever!)


Rant over...folks can move along and apologies for hijacking the thread. No need for anyone to comment or continue down this rabbit hole...but I had to get this out.  @Dazz please moderate this accordingly to avoid me causing a distraction to VPE updates as this thread was intended.



Link to comment
Share on other sites

5 hours ago, blindeshuhn said:

Seems like @Dariusz75 is a bit hyped and impatient. @freezy should take it as an compliment. :D


@galooch is right though.

I know you are right as well @blindeshuhn and I can see that it is likely born out of excitement and passion. A passion we all share here.   

After re-reading my reply, I think it was a bit of an overreaction and just something that I was a bit tired of seeing in general. Apologies @Dariusz75 for using your post as the catalyst.  I know the authors and creators deal with this more often so they are likely more used to it, but it just shouldn’t have to be that way.  Plus, I am genuinely curious why or how anyone could be nothing but respectful and appreciative to those that make this community engine run in the first place. It’s sort of fascinating to me how it cannot be so obvious to someone else. 

I know, I know…welcome to the internet I suppose! :)

Link to comment
Share on other sites

I didn't mean to rush the author, but Freezy hadn't logged in to the VPU for over a month and the last updated file on github was over 2 months ago, so I was wondering if he was still working on the VPE.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry to spawn on this thread but I have a couple of questions.

Is there a page where one can see the state of the different features in progress? I downloaded the packages and after playing around trying to make with a custom game logic, there are certain things that do not work and I cannot tell if this comes from me or it is just not there yet.

(an example: Hit targets are always lowered,  does not matter if I set the switch to NC or not, they are not hittable - drop targets work fine though. Another example are lights being on when playing in editor but off in a build) 

Edited by MARD
missing info
Link to comment
Share on other sites

@Dariusz75 Yeah I admit that's a weird way of asking for any kind of updates. Have you considered that your negative comments might also have a negative effect? Or do you think negative comments trigger positive developments? Have you thought anything at all?


@MARD No, there isn't a list of features in progress. Lights on in the editor is normal, the hit targets are probably a bug. My next thing is going through all the components again and then it'll be fixed if it's a bug. Are you working on a table, or looking to contribute to development?

Link to comment
Share on other sites

On 3/30/2024 at 1:51 AM, freezy said:

@MARD No, there isn't a list of features in progress. Lights on in the editor is normal, the hit targets are probably a bug. My next thing is going through all the components again and then it'll be fixed if it's a bug. Are you working on a table, or looking to contribute to development?

At the moment mostly playing around and I am working on a table - I am not familiar with actual Visual Pinball so I tried to jump natively in Unity. Thanks for the information, I am looking forward to seeing how things go.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...