Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by kirikar67 · Feb 13, 2020 at 10:42 PM · functionnullexception

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)

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tormentoarmagedoom · Feb 14, 2020 at 01:36 AM 0
Share

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.

avatar image kirikar67 tormentoarmagedoom · Feb 14, 2020 at 09:36 AM 0
Share

@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; alt text

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by kirikar67 · Feb 14, 2020 at 10:44 AM

i find a mistake. I didn't attach PlayerMotor to charachter :D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

197 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a relation between color and distance between objects' x coordinates 0 Answers

I have a NullReferenceException problem how do I fix this error 0 Answers

[Space Shooter Tutorial] NullReferenceException: Object reference not set to an instance of an object PlayerController.FixedUpdate () 1 Answer

NullReferenceException Help please :> 1 Answer

ObjectPool for Class Instances using Built-In Array 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges