Function gets null but send is not null
Hi! I just trying to send object in a fucntion but it's get null, while value "focus" gets that meaning. What's wrong?
//some code
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
{
Interactable interactable = hit.collider.GetComponent<Interactable>();
if (interactable != null)
{
SetFocus(interactable);
}
}
}
//some code
void SetFocus (Interactable newFocus)
{
focus = newFocus;
motor.FollowTarget(newFocus);
}
So, when I call motor.FollowTarget(newFocus) it's get null exseption, but focus gets value of newFocus (that is GameObject)
Did yu really debugged the code?
Where newFocus comes from? what is motor? where it comes from? what is FollowTarget? where it comes form?
No info, no answer.
@tormentoarmagedoom Let's see. newFocus that is function argument which it gets That is Player$$anonymous$$otor script. From there we get this fuction. But for some reason when i call motor.FollowTarget it's get null
[RequireComponent(typeof(Nav$$anonymous$$eshAgent))]
public class Player$$anonymous$$otor : $$anonymous$$onoBehaviour
{
Transform target;
Nav$$anonymous$$eshAgent agent;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<Nav$$anonymous$$eshAgent>();
}
void Update ()
{
if (target != null)
{
agent.SetDestination(target.position);
}
}
public void $$anonymous$$oveToPoint (Vector3 point)
{
agent.SetDestination(point);
}
public void FollowTarget (Interactable newTarget)
{
target = newTarget.transform;
}
public void StopFollowingTarget ()
{
target = null;
}
}
And what i find out that send is an Object. I added Debug.Log in SetFocus after focus = newFocus;
Answer by kirikar67 · Feb 14, 2020 at 10:44 AM
i find a mistake. I didn't attach PlayerMotor to charachter :D