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 /
avatar image
1
Question by blueGaia · Jul 22, 2011 at 03:18 AM · parentchildbroadcast

Broadcasting message to multiple children

I am having trouble using broadcast message to deselect and deparant multiple objects.

when selected the gameobjects are parented to a gO named "selected" and upon clicking on terrain or single unit, all selected parents are set to 0.

[Sender]...

 if(Physics.Raycast(ray, hit))
         
             if(hit.transform.CompareTag("UNIT")){
                selected.BroadcastMessage("Deselect",options);
             hit.transform.BroadcastMessage("Select",options);
             }    
             if(hit.transform.CompareTag("Terrain")){
             selected.BroadcastMessage("Deselect",options);
             }

[Reciever]...

 function Select () {
 
     selected = true;
     transform.parent = selectionParent;
 }
 
 function Deselect() {
 
     selected = false;
     transform.parent = null;
 }

But for some reason only one or two is deselected at a time???

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 coastwise · Jul 22, 2011 at 08:41 PM 0
Share

Your logic seems sound... have you tried pausing the game while multiple units are selected and ensuring that they really all do share the same global selectionParent? What you've posted looks ok to me, but maybe somewhere else in your code the parent is being changed.

avatar image blueGaia · Jul 23, 2011 at 03:32 PM 0
Share

yeh, checked that half the reason they are parented is so i can see it in the Hierarchy. Been racking my brains over it for a week now. Is it possible to stick them in an array or something ins$$anonymous$$d ?

1 Reply

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

Answer by DaveA · Jul 23, 2011 at 04:17 PM

If you are reparenting them just to keep like a list of them, use an array or list instead. Only reparent if you really need to have them move or behave as a group. For example, if you had two flocks of birds and you wanted to move some birds from one flock to another. If you're just keeping track of 'selected or not' why not just examine your 'selected' vars? Also consider using layers or tags.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

How to detect child object collisions on parent 3 Answers

Instantiating as a child error 1 Answer

How do I allocate a parent to a gameobject that just got instantiated? 2 Answers

Rotate children around parent pivot 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