// Example list
const myExampleList: Set<PhysicsBody> = new Set(); // <-- create list of PhysicsBody
// How I can add data to the list
const event = physicsHelper.gravitationalField(
gravitationalPosition,
{
radius,
strength,
falloff,
sphere,
affectedBodiesCallback: (bodiesWithData) => {
for (const bodyWithData of bodiesWithData) {
bodyWithData.body.setLinearDamping(1.7);
myExampleList.add(bodyWithData.body); // <-- add some data to the list
}
// ...
},
affectedImpostorsCallback: () => {},
}
)
// ...
myExampleList.forEach((body) => { // <--
body.setLinearDamping(0); // Possible error, because body can be disposed
});
To solve the issue of checking for object disposal, I would like to use the _isDisposed property. But it’s private and only accessible within the PhysicsBody class, which leads to a linter error.
Could you please provide information a PhysicsBody object has been disposed of or not?
Like this one:
Create a getter body.isDisposed that returns true if the object is disposed of.
Create a method body.isExist() that returns false if the object doesn’t exist.
Hey,
I think having public API for this is fine but you can also just check if the body isn’t undefined and if the method is existing:
myExampleList.forEach((body) => {
if (body && body.setLinearDamping) // or more strict like `typeof body.setLinearDamping === 'function'`
body.setLinearDamping(0);
});
No problem, different people have different requirements
I know, but my idea was to reimplement the _isDisposed. So instead of reading the private _isDisposed which you can’t you would create your own isDisposed property.
I didn’t know that @carolhmj will add this feature so lightning fast
If Carol’s solution is fine to you please mark it as Solved.