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 rpettefar · Mar 04, 2014 at 01:41 AM · c#collideristrigger

Why does isTrigger = true not work without an update?

Hi guys. So I'm making a building placement tool for my rts style game. I want to set the building footprint collider to a trigger so that I can check for collisions with other buildings, scenery, etc. However it seems that this does not set the collider to a trigger.

 buildingFottprint.collider.isTrigger = true;

The tick box does not change in the inspector and the trigger behavior isn't happening. I have to manually tick the isTrigger box to get it to function.

After a little poking around I did find that the tick box would change if the tool was active and updates were happening to it.

Can I only change the isTrigger variable in an update function? Does the game object need one update before allowing the change and if so can I trigger one?

Thanks a lot guys.

Comment
Add comment · Show 3
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 highpockets · Mar 04, 2014 at 03:16 AM 0
Share

One of the colliders in the collision has to be a rigidbody for a trigger to work and by the sounds of it, if they are both buildings, they probably don't have rigidbodies. I'm not sure if the results will show in the editor till an update happens anyways.

avatar image rpettefar · Mar 04, 2014 at 08:29 AM 0
Share

This was an issue I had earlier so I gave a rigid body component to the footprint. That's not the issue here though. It starts behaving correctly only when I tick the box manually in the editor during play.

avatar image whydoidoit · Mar 04, 2014 at 08:31 AM 0
Share

I'd disable and renable the collider to kick the physics system into knowing something has changed.

2 Replies

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

Answer by rpettefar · Mar 04, 2014 at 02:41 PM

Whydoidoit had the best solution I think. Just tried it out and works like a charm. I'll copy the comment into the answer for marking as correct

BTW the neatest way to do this might be a coroutine if a delay until physics has started is necessary:

 IEnumerator Start() {
   yield return new WaitForFixedUpdate();
   buildingFootprint.collider.isTrigger = true;   
 }
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
0

Answer by Eidenai · Mar 04, 2014 at 08:57 AM

The only thing I can think of is that you're attempting to apply the change before the collider is actually initialized. Try adding a short delay.

 public bool timerRunning;
 public double seconds;
 
 void Start()
 {
   timerRunning = true;
 }
 
 void Update()
 {
   if(timerRunning)
   {
     seconds += Time.deltaTime;
     
     if(seconds >= 1)
     {     
       seconds = 0;
       buildingFootprint.collider.isTrigger = true;
       DestroyObject(this);
     }
   }
 }
Comment
Add comment · Show 9 · 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 rpettefar · Mar 04, 2014 at 09:41 AM 0
Share

Wow, this does seems a bit much just for turning a trigger on. I thought Unity would have a more elegant way of doing this. I'll try this and whydoidoit's suggestion later today.

avatar image whydoidoit · Mar 04, 2014 at 09:42 AM 0
Share

The physics system doesn't really expect you to convert things between colliders and triggers. Its doing lots of work to model the scene in an efficient manner and changing things like the layer collision matrix just generally isn't what it wants you to do.

avatar image rpettefar · Mar 04, 2014 at 09:47 AM 0
Share

That's fair enough. Then I wonder if there is a better way to initialize my collider as a trigger programmatically then?

avatar image whydoidoit · Mar 04, 2014 at 09:58 AM 0
Share

Have two colliders perhaps - one as a trigger and one as a collider and toggle them on and off. Having a rigidbody attached also might help as it tends to tell physics that stuff might happen - though I'm not sure it will help with this. I think you might be just fine with the disable/enable - it's probably no biggy - just not necessarily what they thought of when they coded it.

avatar image rpettefar · Mar 04, 2014 at 10:12 AM 0
Share

I do have the rigid body and I am not sure about having the two colliders, I only need one as a trigger. I'll be giving this a go later when I can get access to my project. Thanks.

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

23 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

My vehicle goes through walls and floors disregarding all colliders 2 Answers

BoxCollider Overlap OnTriggerEnter Problem 1 Answer

Drag a sprite by its 2D Polygon Collider component 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