Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null check in animator #794

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

f2069
Copy link
Contributor

@f2069 f2069 commented Oct 12, 2024

_isAnimatorSet has null check.

private bool _isAnimatorSet
{
get
{
bool failedChecks = (_animator == null || _animator.runtimeAnimatorController == null);
return !failedChecks;

_canSynchronizeAnimator doesn't have null check.

private bool _canSynchronizeAnimator
{
get
{
bool enabled = (_animator.enabled || _synchronizeWhenDisabled);
bool failedChecks = (!_isAnimatorSet || !enabled);
return !failedChecks;

And periodically we have an error on server side.

MissingReferenceException: The object of type 'Animator' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
FishNet.Component.Animating.NetworkAnimator.get__canSynchronizeAnimator () (at Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs:368)
FishNet.Component.Animating.NetworkAnimator.TimeManager_OnPreTick () (at Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs:556)
FishNet.Managing.Timing.TimeManager.IncreaseTick () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:700)
FishNet.Managing.Timing.TimeManager.<TickUpdate>g__MethodLogic|100_0 () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:376)
FishNet.Managing.Timing.TimeManager.TickUpdate () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:366)
FishNet.Transporting.NetworkReaderLoop.Update () (at Assets/FishNet/Runtime/Transporting/NetworkReaderLoop.cs:28)

@FirstGearGames
Copy link
Owner

I modified it to be a little less redundant. _isAnimatorSet actually does a null check so if we put that first we can save the null check.

            get
            {
                if (!_isAnimatorSet)
                    return false;

                if (_animator.enabled || _synchronizeWhenDisabled)
                    return true;

                return false;
            }

@FirstGearGames FirstGearGames merged commit 0f2b718 into FirstGearGames:main Oct 12, 2024
FirstGearGames pushed a commit that referenced this pull request Oct 12, 2024
- Fixed nested scene NetworkObjects not spawning (#791).
- Added 'Rebuild Selected Scene's Ids' (#789).
- Improved SyncList, removed unused code. (#785).
- Fixed incorrect equality check in SyncList.Set (#784).
- Improved readability for clientHost renderer update methods.
- Improved Dictionaries utilities, removed unused code.
- Fixed collection modified error in ServerObjects.Observers, introduced in 4.5.0 dev branch.
- Fixed NetworkTransform sometimes causing null reference errors with predicted spawning (#792).
- Fixed predicted spawning no longer sends spawn message back to predicted spawner; only confirmation message.
- Improved removed unused code in NetworkAnimator.
- Fixed null check order on NetworkAnimator._canSynchronizeAnimator (#794).
FirstGearGames pushed a commit that referenced this pull request Oct 12, 2024
- Fixed nested scene NetworkObjects not spawning (#791).
- Added 'Rebuild Selected Scene's Ids' (#789).
- Improved SyncList, removed unused code. (#785).
- Fixed incorrect equality check in SyncList.Set (#784).
- Improved readability for clientHost renderer update methods.
- Improved Dictionaries utilities, removed unused code.
- Fixed collection modified error in ServerObjects.Observers, introduced in 4.5.0 dev branch.
- Fixed NetworkTransform sometimes causing null reference errors with predicted spawning (#792).
- Fixed predicted spawning no longer sends spawn message back to predicted spawner; only confirmation message.
- Improved removed unused code in NetworkAnimator.
- Fixed null check order on NetworkAnimator._canSynchronizeAnimator (#794).
@f2069 f2069 deleted the animator.nullcheck branch October 13, 2024 09:21
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