Transform of an object received by a raycast, not accepted by function demanding a transform of an object.
Debug.Log(worldInteraction.lastInteractionObject.transform);
cameraController.SetMainTarget(worldInteraction.lastInteractionObject.transform);
This line of code returns the following in the debugger:
NPCInstance (UnityEngine.Transform)
UnityEngine.Debug:Log (object)
DisableInputOnConversation:ConversationStart () (at Assets/DisableInputOnConversation.cs:42)
DialogueEditor.ConversationManager:StartConversation (DialogueEditor.NPCConversation) (at Assets/Imports/DialogueEditor/Assets/Scripts/UI/ConversationManager.cs:151)
NPC:Interact () (at Assets/Scripts/WorldInteraction/NPC.cs:12)
WorldInteraction:GetCenterObject () (at Assets/Scripts/WorldInteraction.cs:33)
WorldInteraction:Update () (at Assets/Scripts/WorldInteraction.cs:17)
NullReferenceException: Object reference not set to an instance of an object
DisableInputOnConversation.ConversationStart () (at Assets/DisableInputOnConversation.cs:43)
DialogueEditor.ConversationManager.StartConversation (DialogueEditor.NPCConversation conversation) (at Assets/Imports/DialogueEditor/Assets/Scripts/UI/ConversationManager.cs:151)
NPC.Interact () (at Assets/Scripts/WorldInteraction/NPC.cs:12)
WorldInteraction.GetCenterObject () (at Assets/Scripts/WorldInteraction.cs:33)
WorldInteraction.Update () (at Assets/Scripts/WorldInteraction.cs:17)
The refrence is set in the following block:
public class WorldInteraction : MonoBehaviour {
public GameObject lastInteractionObject;
public GameObject GetCenterObject() {
Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, interactionRange)) {
GameObject interactedObject = hit.collider.gameObject;
if (interactedObject.tag == "Interactable") {
lastInteractionObject = interactedObject;
interactedObject.GetComponent<Interactable>().Interact();
} else {
// Debug.Log("Non-Interactable Object");
}
return interactedObject;
} else {
// Debug.Log("Error: Raycast hit nothing.");
return null;
}
}
}
the function that requires the Transform.
public void SetMainTarget(Transform newTarget)
As you can see, it indeed returns an instance of an object. Yet it doesn’t? I can’t figure out why the function doesn’t accept that as an instance.
Thank you in advance.