Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
1
Question by snoboxstudio · Jan 24 at 07:50 PM · rigidbody2dcollider2donclick

On click, select game object -working with objects in scene but not instantiated objects

Hey everyone! I hope I can get some help with this issue, because it is BOGGLING my mind. I have created an RTS (starcraft-esque) game for Newgrounds' Pixel Day 2022 (it is called BitBase if you want to try it out and get a better idea of the issues I'm having lol, but this post is about one issue in particular).

  • Main Issue: When I run the game in Unity, I have 5 'peons' in the scene, along with a few resources for them to gather and a central node, and I am able to left-click and 'select' those units without any issue, but new units spawned in WILL NOT activate their selected function this way. The way the game functions right now, you can drag and select units, which works for all as I have a script on a boxCollider and lineRenderer that does all of my detection for that. Also functioning is a UI script that pops an info panel when a unit is left-clicked (not click and dragged)..

  • Troubleshooting steps I have taken;

  1. I have broken down the units that are in the scene bit by bit and they are NO different than the units being instantiated (they are just prefabs that I dragged into the scene, but the same prefab being instantiated).

  2. Changed my Ui script to access the clicked unit script (using PhysicsRaycast2D then getting the hit collider's Unit component and tried to FORCE the selector active that way... to no avail)

  3. Tried an OnClick function on the Unit monobehaviour script

  4. There are no colliders blocking the unit, the units have rigidbodies, they are on the proper detection layer and it IS detecting the unit being clicked, because it is popping the UI info, but somehow getting lost in actually accessing the Unit... :S

There is probably something super simple that I'm missing or a conflict in the UI scripts possibly, but I'm at my wits end here. Also, I am self taught, so I apologize if any of my terminology is improper; if there is any confusion please let me know and I will try to provide more info or screenshots!

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
0
Best Answer

Answer by snoboxstudio · Jan 27 at 01:35 AM

To resolve this thread; it appears to be some faulty logic on my part (shocker lol). I broke down my scripts bit by bit and found a redundant ! that was probably throwing things off. After reorganizing and simplifying some conditions, the function now reliably works! But it was strange that it was working, at all, if the logic was flawed.

@privatecontractor thanks again for trying to help!

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
avatar image
1

Answer by privatecontractor · Jan 24 at 08:08 PM

Hi @snoboxstudio,

Maybe somewhere you are checking for name of selected GameObjects... and new Instantiated 'peons' have '(clone)' added?

Did your check new Instantiated 'peons' during pause in gameplay did all of they [Serializefield] are still atached? Maybe some of components weren't assigned after Instantiate?

Hope will help, let me know.

Comment
Add comment · Show 7 · 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 privatecontractor · Jan 24 at 08:10 PM 1
Share

Also maybe Tags?

avatar image snoboxstudio · Jan 24 at 08:36 PM 0
Share

Thank you so much for the answer @privatecontractor ! I am checking for the tag "Unit", not the name, that is definitely the first thing I changed xD there was one odd thing where a rally point was being passed to the newly produced unit and then not beco$$anonymous$$g null, which I was able to fix thanks to this comment -so there's something! haha

Other than that, everything is being assigned and attached properly, everything executes 100% except the click to select on the new units O.o I went and checked out my Instantiation function too, and I'm not changing/effecting the prefab's state in a way that should break this... Just to make sure, I checked that there were no overrides on the prefabs existing in the scene, and dragged new prefabs in which ALSO work fine with the click function, but still not the instantiated objects! What the heck am I missing!? D:

avatar image privatecontractor snoboxstudio · Jan 24 at 08:59 PM 1
Share

@snoboxstudio, maybe when you drag- drop prefab directly to scene it's going to main root in hierarchy.... and new Instantiated prefabs going to some parent which affecting them?

avatar image snoboxstudio privatecontractor · Jan 24 at 09:44 PM 0
Share

Apologies in advance for this novel; I was thinking that the hierarchy had something to do with it, but when I placed the (working) prefabs in the scene I put some within the parent object they're Instantiated into and some outside of it in the main hierarchy, they were able to be clicked and selected! But the newly Instantiated objects are still unclickable (not.. unclickable.. but 'unselectable' when left-clicking on them).
And just to clarify a bit more, when newly instantiated units are left-clicked a pop up menu references their script and is able to get the specific unit name and information(health, shield, cost, etc). But even when I moved the Unit's 'Selected' function to be called right there in the UI manager, on that same pop up function, it won't do it! D:

I might as well answer your second comment in this one too lol apologies its taking me a while to double check these things and then write out my response.. in addition to that, my power has been going on and off all day -_-

I am not sure what you mean by 'using an event for the click-drag inside' - do you mean a UI event? Not a function within the C# scripts? If so, then no xD And just to make sure we're on the same page in this regard too, the click-drag is working; while mouse is down I have a script that creates a box with a line rendered and adds a collider component.
But the OnMouseDown function isn't triggering a specific function on the Unit's script to set a bool true and setActive an indicator.. it seems so simple and that it's working on pre-instantiated objects means that the function itself is valid but something is getting lost in the call... I feel like my brain is dancing around the answer, grrn...

Show more comments

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

140 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 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

When i try to add Collider2D or Rigidbody2D through code to prefab gameObject after stopping game the added component remain added to the prefab obejct. 0 Answers

How to select the trigger layer on a Box Collider 2D 2 Answers

Disable click action when collision 1 Answer

Scaling colliders up and down over time 1 Answer

Velocity doesnt change properly 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