Skip to content

Add R3.CompositeDisposable support to AddTo extension#277

Open
YoruYomix wants to merge 1 commit intoannulusgames:mainfrom
YoruYomix:add-r3-compositedisposable
Open

Add R3.CompositeDisposable support to AddTo extension#277
YoruYomix wants to merge 1 commit intoannulusgames:mainfrom
YoruYomix:add-r3-compositedisposable

Conversation

@YoruYomix
Copy link
Copy Markdown

Adds AddTo(R3.CompositeDisposable) overload for MotionHandle.

This allows motion handles to be added to R3's CompositeDisposable,
which automatically cancels the motion when disposed.

@nuskey8
Copy link
Copy Markdown
Member

nuskey8 commented Apr 2, 2026

Wouldn't handle.ToDisposable().AddTo(compositeDisposable) be enough?

@YoruYomix
Copy link
Copy Markdown
Author

YoruYomix commented Apr 3, 2026

It works in simple cases, but breaks down when you need to chain further after AddTo. A common real-world pattern is:

await LMotion.Create(0f, _originalColor.a, _duration)
  .WithEase(Ease.OutSine)
  .BindToColorA(_image)
  .AddTo(compositeDisposable)
  .ToUniTask(cancellationToken);

Without this overload, the chain must be split into separate statements because ToDisposable() loses the MotionHandle, making .ToUniTask() unreachable:

var handle = LMotion.Create(0f, _originalColor.a, _duration)
  .WithEase(Ease.OutSine)
  .BindToColorA(_image);

handle.ToDisposable().AddTo(compositeDisposable)

await handle.ToUniTask(cancellationToken);

Since AddTo(CompositeDisposable) returns this (MotionHandle), the chain stays intact — ToDisposable() breaks it by converting to IDisposable early. So while the workaround is functional, it forces boilerplate that the overload cleanly eliminates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants