Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Maxpeinas · Apr 14, 2014 at 09:02 AM · objectlistconvertoverloadinvalid arguments

Error adding Vector3 to Object list

Hi all. So here is the code in C# and i get errors when trying to add Vector3 direction to list:

 List<Object> arr;

 void DrawRoute(Vector3 direction) {
         if(step == 0) {
             tempPos = tempPos + direction;
             arr.Add(direction);
             step++;
         }
         else {
             tempPos = tempPos + direction;
             arr.Add(direction);
             step++;
         }
     }

It works perfectly in JS, but somehow none of the methods from google worked in c# and i can't even compile it, because it throws errors. If i change list type to Vector3 it works, but i need to store different type of variables in it and it works in JS with "Object" type, so any help would be appreciated. I get following errors:

CS1503: Argument '#1' cannot convert 'UnityEngine.Vector3' expression to type 'UnityEngine.Object'

and

CS1502: The best overloaded method match for 'System.Collections.Generic .List.Add(UnityEngine.Object)' has some invalid arguments

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

1 Reply

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

Answer by fafase · Apr 14, 2014 at 09:05 AM

Try with object lower o on the front.

Vector3 is a struct so it does not inherits from Object but it should inherits from object which the .NET implementation and is the top class of all, even UnityEngine.Object.

Comment
Add comment · Show 3 · 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 Maxpeinas · Apr 14, 2014 at 10:39 AM 0
Share

Don't know why i didn't thought about it before...Thanks a lot !

avatar image fafase · Apr 14, 2014 at 10:44 AM 0
Share

Though this kind of go against what C# is all about, typesafe program$$anonymous$$g. You use a list of objects, probably you are storing other type of objects, well personal point of view, I don't recommended it, you better have a list for each type. But this is all personal.

avatar image Maxpeinas · Apr 14, 2014 at 11:16 AM 0
Share

I will keep that in $$anonymous$$d, thanks. Just all of my scripts are based on this list mainly and I am just converting them from JS to C#.

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

21 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

Related Questions

A node in a childnode? 1 Answer

Object Method returning null when calling Object List from another Class 1 Answer

Is there an easy way to add an array of raycasthit2Ds to a list? (javascript) 2 Answers

Removing null object from array in unity 0 Answers

Array - Convert Object into Int 5 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