Problem statement:
Currently in order to make interactable object it is required:
Basically two changes I have made:
Currently in order to make interactable object it is required:
- Add Interactable component to object
- Add IInteractableTarget component with logic that will do the actual job
- Fill ID for each single prefab object
Basically two changes I have made:
- Changed Awake signature from private to protected so that it can be overriden while code in Interactable.Awake() can be still executed
- Moved array creation to the top of the method so that they are always available. As far as I can tell if they are present but empty then it is still fine (nothing broken) but at the same time no null pointers
C#:
protected virtual void Awake()
{
m_InteractableTargets = new IInteractableTarget[m_Targets.Length];
m_IKTargets = GetComponentsInChildren<AbilityIKTarget>();
if (m_Targets == null || m_Targets.Length == 0)
{
Debug.LogError("Error: An IInteractableTarget must be specified in the Targets field.");
return;
}
for (int i = 0; i < m_Targets.Length; ++i)
{
if (m_Targets[i] == null || !(m_Targets[i] is IInteractableTarget))
{
Debug.LogError("Error: element " + i + " of the Targets array is null or does not subscribe to the IInteractableTarget iterface.");
}
else
{
m_InteractableTargets[i] = m_Targets[i] as IInteractableTarget;
}
}
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
m_NetworkInteractable = gameObject.GetCachedComponent<INetworkInteractableMonitor>();
#endif
}
Last edited: