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 /
  • Help Room /
avatar image
0
Question by smirlianos · Jun 21, 2013 at 09:27 AM · instantiatecollidertriggersphere

OnTriggerStay Doesn't work if not moving

Hello,


if I instantiate a sphere with a trigger collider "inside" of a wall, it doesn't happen what is supposed to happen.

If I instantiate the sphere outside of the wall and move it into the wall, it works.

Why, and how can I solve it?

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

Answer by TonyLi · Jun 21, 2013 at 01:46 PM

Review all the conditions on the Rigidbody Sleeping page. Are your objects set up correctly with rigidbodies or static colliders? Given your description, the sphere should probably be a static collider marked Is Trigger, and the sphere should have a rigidbody.

If you instantiate one collider inside another, it will not register OnTriggerEnter messages, but it should register OnTriggerStay.

Comment
Add comment · Show 23 · 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 smirlianos · Jun 21, 2013 at 02:08 PM 0
Share

The sphere is instantiated from the $$anonymous$$ainCharacter, as a way to make an attack. It Instantiates in front of him.

If I get clse to the wall and hit the attack button, the sphere would be instantiated inside the wall, but nothing will happen despite the "OnTriggerStay" function it has...

avatar image TonyLi · Jun 21, 2013 at 06:03 PM 0
Share

Please post screenshots of the fully-expanded Inspector view for the sphere and the wall.

avatar image smirlianos · Jun 22, 2013 at 12:08 PM 0
Share

Sorry for late answer.

Here are the screenshots Wall

ball

avatar image TonyLi · Jun 22, 2013 at 02:09 PM 0
Share

Those game objects look good to me. Can you post your Js_Attacks script? I suspect that you need to use OnTriggerStay ins$$anonymous$$d of OnCollisionStay. I'll suggest that as an answer.

avatar image TonyLi · Jun 29, 2013 at 12:55 AM 1
Share

Here's a unitypackage that demonstrates a combination that works: https://dl.dropboxusercontent.com/u/7669211/BallWallCollision.unitypackage

Import it and open the scene in the Test folder. When you press play, you can move around with the first person controller. The X key spawns and destroys the ball. The ball prints collisions in the console.

It's on my public dropbox, so no guarantees that it'll be there forever. But if someone's reading this in the future and it's gone, the settings and code are in the previous comments. Here's the ball-spawning code:

 public class SpawnBall : $$anonymous$$onoBehaviour {
     
     public GameObject ballPrefab;
     
     private GameObject ball = null;
 
     void Update() {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.X)) {
             if (ball == null) {
                 ball = Instantiate(ballPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                 ball.transform.parent = this.transform;
                 ball.transform.localPosition = new Vector3(0f ,1f, 1f);
             } else {
                 Destroy(ball);
                 ball = null;
             }
         }
     }
 }
Show more comments
avatar image
1

Answer by YagoRG · May 01, 2021 at 03:42 PM

I know I am way too late for this... but just in case anyone stumbles upon the same problem here's what worked for me.

I solved it by calling the rigidbody and applying a foce of zero to it inside the void Update, that way it won't go to sleep.

In my case was for a 2D game so it ended up looking like this:

 Rigidbody2D rb;
 
 // Update is called once per frame
     void Update()
     {
         rb.AddForce(Vector2.zero);
     }

I bet there's better ways to do this but this one is really simple and works for a fast and easy fix.

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 huntermccoid · Sep 08, 2021 at 01:45 AM 0
Share

Lifesaver! Thank you for posting late, you saved me so much time and struggle!

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

18 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

Related Questions

Destroy instatiate object on trigger enter / collision,destroy instantiate prefab on trigger enter 0 Answers

My code is instantiating many prefabs, i only want one. 1 Answer

How do I differentiate between the triggers? 1 Answer

TIme -Bomb exploding issue 0 Answers

OnTriggerEnter2D not working 2 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