02-02-2026, 01:34 PM
(This post was last modified: 02-02-2026, 05:04 PM by josemendez.)
(02-02-2026, 11:56 AM)Qriva0 Wrote: I think this is cause of my problems described in the other thread. Stitcher can be disabled during simulation, and the same happens on destroy and on application quit (called also when exiting playmode). Solver removes actors, but it does not take into account that simulation is still running and doing this is not allowed:
Unity may call OnDestroy, OnEnable or OnDisable() at any time. Removing an actor doesn't really touch any memory that threads read/write from during simulation, so removing an actor has no ill effect: it just pushes the indices of particles belonging to the actor to a free list so that they can be reused by actors added afterwards (adding an actor to the solver is a buffered operation, guaranteed to not happen during simulation). Constraints are simply set dirty and updated at the start of the next simulation step. This is an expensive operation, but unfortunately it's the way it works in Obi 7.
Upon removing the last actor, the solver calls its Teardown() method which does free up resources that may be in use by other threads, but it waits for the current simulation step (if any) to complete before destroying any resources that may be used by other threads.
(02-02-2026, 11:56 AM)Qriva0 Wrote: The fact I need to manage data for simulation this way is not just clunky, but does not work
In Obi 7 constraints stuff wasn't really designed to be extendable by users, so I totally understand it feels clunky and brittle: unfortunately it is.
When dealing with multithreaded code, you can't modify memory accessed by multiple threads while the threads are running or you risk race conditions. There's basically 3 ways to allow users to interact with an API that uses multithreading under the hood:
- Have a boolean "are multiple threads currently running" and forbid calls to specific methods when that boolean is true, forcing the main thread to poll this boolean until it's allowed to do whatever it is trying to do.
- Force users to do things in specific callbacks called by the engine at a specific point in time that's guaranteed to have no threading issues. This is a slightly cleaner version of method #1.
- Double-buffer all memory that may be modified from the main thread while the simulation is working on a copy of it. As far as API cleanliness goes this is the best method as for the most part it makes multithreading transparent to the user, but it can be memory hungry.
(02-02-2026, 11:56 AM)Qriva0 Wrote: so I hope there will be proper improvement in Obi 8.
In Obi 7 there's no explicit safely rails in place. Executing constraint code at the wrong time can (and will) blow things up.
Obi 8 uses all of the above methods, mainly the third one. This means you can add/remove/modify constraints while simulation is running, which simplifies things and makes writing code that extends the engine a great deal more robust. We're making sure all constraint API calls are safe to use at any time, those that cannot have immediate effect are either double buffered or their execution is deferred until there's only one active execution thread.
(02-02-2026, 11:56 AM)Qriva0 Wrote: Is there reasonable way to manage this with older obi versions?
What is it exactly that you're to trying to do? I assume it's some kind of pin constraint/stitch constraint creation at runtime? could you give a few more details so I can recommend the best approach to it in Obi 7?
kind regards

