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 /
This question was closed Sep 01, 2013 at 09:49 PM by Kiloblargh for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Kiloblargh · Sep 01, 2013 at 07:59 PM · listgenericswarningindexof

Implicit Downcast warning from "List.IndexOf" ...Bad? Unavoidable?

When I try to do something like this:

gCon.ReturnFinalPos (gCon.freeLetters.IndexOf (this as Object), Vector2.Lerp (remotePos, targetPos2, 0.5));

or

if (gCon.displacedLetters.ContainsKey (gCon.freeLetters.IndexOf (this as Object)))

I get

 BCW0028: WARNING: Implicit downcast from 'Object' to 'LoneLetter'.


I know what the warning means, I added the "as Object" because IndexOf in a generic list or dictionary won't take the the variable type of whatever it's a List. of, which seems stupid to me but that's how it works, it threw an error if I gave it anything other than an Object.

The closest I could find to a solution was a for ... in statement where the type is left to the compiler's imagination, but I don't think that applies to what I'm trying to do.

The reason I'm getting array indexes in the first place is so I can keep local and remote copies of an object in sync over a network with RPC calls ( for 2 players, each has an 'allMyUnits' list and an 'allYourUnits' list, whose indices and contents are mirrored crosswise in a consistent way. ) The script on the individual unit figures out its place on the game controller's local unit list, then sends that as a byte to the other player with the move order, the other player's game controller script receives the RPC and then passes the order on to the script of the matching index on the remote unit list.

Am I doing it wrong?

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

  • Sort: 
avatar image
1
Best Answer

Answer by DESTRUKTORR · Sep 01, 2013 at 08:23 PM

http://msdn.microsoft.com/en-us/library/e4w08k17.aspx

It most certainly does take the object type with it. It's a generic method.

Generally, though, I don't like having to use IndexOf, Find, Search, Contains, etc. with standard lists. It's too costly, and there's much better collection types for those sorts of things, assuming they are an option (if not, there's usually still a method of getting around that issue).

If your object extends the class your list uses, it should need no casting. Casting is usually used when an object can be used as a child of the class it was declared as, e.g.

 SuperClass obj = new SubClass();
 (obj as SubClass).SubClassMethod();

Though this operation on its own is superfluous, it should illustrate my point clearly enough.

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

Follow this Question

Answers Answers and Comments

17 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

Related Questions

A node in a childnode? 1 Answer

Grab a specific item from a list 3 Answers

How to get smallest element and key from int list 1 Answer

How to add to a list excluding certain items 1 Answer

how to get a random integer in a list? 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