Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
avatar image
0
Question by abstractfragment · Feb 14, 2018 at 07:42 PM · collisioninterfaceforeachargumentexceptionderived-class

Derives from MonoBehaviour or Component or is an interface. Error

I am coding a script in which an enemy who when it finds a set of footprints will start following the footprints to find the player. It works fairly well with a few issues in the movement related only to what I can assume is the navmesh but I get this error.

ArgumentException: GetComponent requires that the requested component 'Vector3' derives from MonoBehaviour or Component or is an interface.

It doesn't stop the enemy from following the footsteps and everything is still mostly functional but I still want to get rid of this bug.

Here is my code. It's not very clean or organized or probably optimal as it is just me working on it.

 void OnTriggerStay(Collider col)
     {
         //If the wolf stumbles upon any footstep trackers this gets their specific instance and sequence number.
         if (col.gameObject.CompareTag("tracking")) {
             footstepTracking thisFoot = col.GetComponent<footstepTracking>();
             if (PlayerInSight == false) {
                 this.gameObject.GetComponent <NavMeshAgent> ().destination = nextFootLoc;
             }
         
 
             foreach (GameObject footprint in footTrack){
                 footstepTracking thatFoot = footprint.GetComponent<footstepTracking>();
                 Debug.Log (thatFoot.Seq);
                 if (thatFoot.Seq == (thisFoot.Seq + 1)) {
                     nextFootLoc = thatFoot.GetComponent<Vector3> ();
                     Debug.Log ("The next footprint is" + thatFoot.Seq);
                 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Commoble · Feb 15, 2018 at 06:08 PM

Vector3 is not a component. If you need the position of a GameObject, that object and all Components attached to it have a transform field that contains the Transform of that object, so you can use thatFoot.transform.position to get the Vector3 position of the object your footstepTracking script is on.


(Deleted my previous answer as I realized it was not the best answer)

Comment
Add comment · Show 1 · 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
avatar image TreyH · Feb 15, 2018 at 08:18 PM 0
Share

Yeah, it's hard to tell exactly what's going on here as we don't have your footstepTracking component or know what footTrack is, but your bottom block is probably going to be something like :

 foreach (GameObject footprint in footTrack)
 {
     footstepTracking thatFoot = footprint.GetComponent<footstepTracking>();
     
     if (thatFoot == null)
         continue;
     
     Debug.Log (thatFoot.Seq);
     if (thatFoot.Seq == (thisFoot.Seq + 1)) 
     {
         nextFootLoc = thatFoot.transform.position;
         Debug.Log ("The next footprint is" + thatFoot.Seq);
         break;
     }
 }

avatar image
0

Answer by yummy81 · Feb 15, 2018 at 06:56 PM

When you call GetComponent method, it requires that the component you want to get reference to is derived from: MonoBehaviour, Component or is an interface. Vector3 does not derive from any of them, because its chain of inheritence looks as follows:

 UnityEngine.Vector3
 System.ValueType
 System.Object
 
 
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

123 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

Related Questions

foreach loop in OnCollisionStay 1 Answer

Is there a way to organize tracking of collisions? 0 Answers

Particle effect collision with some damage. 0 Answers

[C#] Calling Interface from Array of MonoBehaviour 2 Answers

Having Converision error with foreach loops 3 Answers


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