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 Ossyahn · Jan 21, 2015 at 04:41 PM · rigidbodyvariablesscriptingproblemsleepingwakeup

Do asleep rigidbodies prevent from modifying its variables in runtime?

Hello,

I have a player gameObject with some scripts attatched to it. The player gameObject is with 0 movement most of the time, and I have different scripts modifying variables within each other. But the problem is that they are not modifying each other, and I think that may be because the gameObject that contains the scripts is asleep. And even if I'm right I don't manage to solve it just with the WakeUp() function.

For example, I have one script that makes the player pick up an object when hes on reach (PickUpObject.cs), and another one that makes him throw it (ThrowObject.cs). If the player doesn't throws it and moves, PickUpObject.cs returns the object where it was before picking it. In this case the objects are ingredients (because the game theme):

 public class PickUpObject : MonoBehaviour {
 
     public GameObject ingredient;
     public bool hasIngredient;
 

and

 public class ThrowObject : MonoBehaviour {

 PickUpObject pickUpObject;

 void Awake () {
     pickUpObject = GetComponent<PickUpObject> ();
 }

 void Throw () {
 
         pickUpObject.ingredient.rigidbody.useGravity = true;
         pickUpObject.ingredient.rigidbody.AddForce(angle*force, ForceMode.Impulse);
 
         rigidbody.WakeUp ();
 
         if (rigidbody.IsSleeping ()){
             print ("is sleeping");
         }
 
         pickUpObject.hasIngredient = false;
         print (pickUpObject.hasIngredient);
 
     }
 }


There's more logic I didnt posted here, but basically, in order to not put down an already thrown object, when it's thrown I want to set hasIngredient to false, and the funny thing is that when I print the state of hasIngredient from the ThrowObject script it prints false, but in the inspector (where PickUpObjects.cs shows it because is public) it appears as true, and in fact the game behaves as such, so I assume that it's not being really modified. And also that there're an instance of PickUpObject where its false (the one that ThrowObject.cs picks) and the original at true? Are not this variables stored by reference? Is all that because the object is sleeping?

I also tried to wake up the gameObject, even waiting to the next frame to print if its been awake, but always prints the "is sleeping" string.

How does people deal with this kind of thing?

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

Answer by Owen-Reynolds · Jan 21, 2015 at 06:17 PM

No, sleeping rigidbodies don't have any effect on the script. The script doesn't care about RB.sleep status (I've never directly tested this, but I feel like I would have noticed it by now. Could test with a script that sleeps the RB, counts off 300 frames, then prints something.) All sleep does is tell the physics step to skip that object.

You're probably seeing the "is sleeping" message from different scripts or previous frames. Try having public bool slp; with slp=rigidbody.Issleeping(); in Update, which will allow you to "see" the current sleep status of the object.

This looks like a typical debugging dead-end. Thinking about this sleep stuff is preventing you from finding the real code bug.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Applying Constant Force on Multiple Axes Via Javascript? 1 Answer

All objects sleeping not working 1 Answer

Rigidbody Sleeping 4 Answers

List of reserved variables such as transform and rigidbody 1 Answer

Rigidbody.IsSleeping() VS Rigidbody Velocity Comparison. Performance question for object stop detection. 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