Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 DoctorSauce · Jan 11, 2014 at 04:16 AM · c#gameobjectinstantiateoverlap

How to not instantiate an object if there is another object there?

Alrighty this might be a tough question, I searched around online but the only question on this that I found ended up not having a right answer, so here goes. I have a random generation thing set up where basically, when the scene starts, one room is randomly instantiated. Then that room creates hallways coming off of it, and those hallways create rooms on the end of them, and those rooms create more hallways, on and on until a certain limit is reached. The obvious problem that I have here is rooms being instantiated on top of other rooms, or hallways cutting through other hallways, etc. And obviously, this won't work well for a video game. So I can't post all 5 scripts I have that do this, but basically this is the line of code I am using to instantiate whatever object.

 Instantiate(chosenDungeon,spawnPos, Quaternion.identity);

What I want is to check before doing this code whether or not there is already an object where it is going to instantiate, or whether or not it is going to overlap another object. I can't just check for an object at the spawnPos, because that won't stop a hallway from overlapping another hallway. I need it to check whether or not it will overlap another object before it instantiates. Is there any possible way to do this? Thanks in advance, I know this is probably a tough question.

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 KellyThomas · Jan 11, 2014 at 04:24 AM

`renderer.bounds` should do it:

With this axis aligned bounding you can perform an `Intersects()` check against each of your other dungeon segments.

Comment
Add comment · Show 1 · 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 DoctorSauce · Jan 11, 2014 at 04:29 AM 0
Share

You're a genius... Thank you so much.

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

19 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

Related Questions

Instantiated GameObject Not Rendering 1 Answer

How can I add the OnTriggerEnter function to all game objects that I instantiate? 1 Answer

C# instantiate into list 2 Answers

Distribute terrain in zones 3 Answers

Instantiate prefab at specific path 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