skinwalker
Member
Hi,
I have a hair with physics using BonesStimulator and during "Fly" state I disable the physics, because it looks very weird, so this is my code, but I'm pretty sure its going to be replicable with any other script not just BonesStimulator.
The problem comes when I destroy the hair (unequip it) and I use my fly ability, i get this error, pointing to Ability.cs line 577 "
StateManager.SetState(m_GameObject, m_State, active);
"
The Error
MissingReferenceException: The object of type 'BonesStimulator' 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.
I guess the state system keeps cache of all the objects, but now that the BonesStimulator (hair) is destroyed it fires this error because its null. How can I fix that?
I have a hair with physics using BonesStimulator and during "Fly" state I disable the physics, because it looks very weird, so this is my code, but I'm pretty sure its going to be replicable with any other script not just BonesStimulator.
C#:
public class EnableBonesStimulatorStateBehavior : StateBehavior
{
[SerializeField] protected bool _isEnabled;
[SerializeField] private BonesStimulator _bonesStimulator;
public bool IsEnabled
{
get => _isEnabled;
set
{
_isEnabled = value;
_bonesStimulator.enabled = value;
}
}
}
The problem comes when I destroy the hair (unequip it) and I use my fly ability, i get this error, pointing to Ability.cs line 577 "
StateManager.SetState(m_GameObject, m_State, active);
"
The Error
MissingReferenceException: The object of type 'BonesStimulator' 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.
I guess the state system keeps cache of all the objects, but now that the BonesStimulator (hair) is destroyed it fires this error because its null. How can I fix that?