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 Crayz · Dec 08, 2014 at 03:40 AM · transformlistparentrtsselections

C#, expensive or inexpensive?

I've been tinkering around with RTS style gameplay, coming up with various ways of handling unit selection. The maximum amount of units I want able to be selected at once is 24, so there's not going to be a LOT of data being passed around.

The first solution I came up with was an empty gameobject with a script attached handling selection methods. This object has two empty children, Active & Inactive. When a unit is tagged for selection its parent is transferred to the Active object, when a unit is no longer selected its transferred to the Inactive object.

If it's set up this way I can quickly and easily iterate through Active's children when I need to move around my selected units, or handle the Inactive units through a quick iteration as well.

The other solution I tried was adding units to a list when they're selected, then removing them from the list when they are unselected. This was more of a pain in the ass getting things to communicate properly between the units and selection handling, as well as converting my list to an array in order to iterate through it. I also found myself using Transform.GetComponent quite often.

My question is, is one method slower/faster? Should I avoid parenting or lists for a task like this? Anybody know of any other solutions that might be better?

If anybody has some object oriented solutions for this using inheritance, interfaces, or whatever else there may be, I'd like to see.

Thanks for reading

Comment
Add comment · Show 1
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 Crayz · Dec 08, 2014 at 06:51 AM 0
Share

Alright, I've re-written my classes for the second or third time today, finally come to something that I can be comfortable with. I used HashSet and it's working out nicely.

Before I was trying to list all selected units within list in my selection controller as well as setting the unit itself to selected within the unit's class, which was causing a little shitstorm trying to get things to sync up nicely. Now all selected units are stored in a single place.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kiwasi · Dec 08, 2014 at 03:47 AM

While not a full answer, I would definitely suggest a HashSet over a list. Lists are only for if order is important.

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

26 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

Related Questions

A node in a childnode? 1 Answer

Properly Rotating Child Objects by Script 1 Answer

use list of gameobjects transform in raycast 0 Answers

Problem retrieving transform.position after parent rotation 1 Answer

Make a GameObject child to a "Dragged Reference" GameObject doesn't work! 0 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