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 instruct9r · Jul 07, 2014 at 09:39 PM · functionyieldstoppublic

Coud public variables with same names cause problems?

I have pretty weird problem.

First i'll explain what's happening.

I have a character and in the MovementScript there is one function that is killing the player and moving it back to the last CheckPoint. The function simply stops the player from moving, then deactivating only the geometries, not the whole gameObject of the character, so the scripts, can continue working. These deactivations and activations are separated by simple yields with 0.5 to 1.5 seconds.

There are holes in the game and when the player falls in them, he passes through a trigger, that simply calls the function that kills the player. It works just perfectly.

There are also characters, that shoot bullets in the game and when that bullet hits the player, it calls the same function, for killing the player. But when the bullet calls the Kill function it get's executed just untill the first yield and then stops. So the player dissapears and doesn't go back to the checkPoint.

There are no errors, no nothing. It just stops at the yield and happens only when bullet hits player.

The bullet have 2 public variables "speed" and "rotateSpeed". I just found, that if i change the variable of the bullet, from speed, to bulletSpeed, the Kill function is executed untill the end.

So if i have 2 variables on completely different objects, that are public (Not Static), is that a problem???

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

Answer by legion_44 · Jul 07, 2014 at 10:00 PM

Hmm.. are you calling the kill function with some parameters? Ex. speed (which is then used in yield)? The if you make it just Kill(speed), you're referencing speed from bullet not from the player script. It will be hard to quess without your code ;).

Comment
Add comment · Show 4 · 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 instruct9r · Jul 07, 2014 at 10:12 PM 0
Share

hm. I tried changing the var names, but that doesn't work either.. So what the hell is happening 0_0

This is the code, that is attached to the bullet:

 // Public Variables

 public var ballSpeed            : float = 1.0;        // The speed of the ball

 public var ballRotateSpeed        : float = 1.0;        // The speed of rotation

 

 //@HideInInspector

 public var flowerDirection    : Vector3 = Vector3.up;    // Feeded from the flowers, that the ball is in

 

 // Private Variables

 private var trans            : Transform;

 private var ftDirection        : Vector3 = Vector3(0, 1, 0);    // The direction, that the ball will be flying at

 

 function Awake()

 {

     trans = transform;

 }

 

 function Update()

 {

     ftDirection = flowerDirection * ballSpeed;    // Update the direction, every frame, from the flowerDirection

     trans.Translate(ftDirection * Time.deltaTime, Space.World);    // Translate the object with deltaTime

     trans.Rotate(Random.Range(0, ballRotateSpeed), Random.Range(0, ballRotateSpeed), Random.Range(0, ballRotateSpeed));

 }

 

 function OnTriggerEnter (col : Collider)

 {

     if (col.tag == Tags.player)

     {

         col.transform.GetComponent(Player$$anonymous$$ovement_JS).BackToCheckPoint();    // If ball hit player, it kills it

     }

 }
avatar image instruct9r · Jul 07, 2014 at 10:12 PM 0
Share

Now. Since the player script is 400 lines of code i will only attach, what's in the BackToCheckPoint() function

 function BackToCheckPoint()
 {
     // Collect information about Character
     var rabyGeo            : Transform = trans.Find("RabyGeos_grp");        // Get the geo group
     var curGravity        : float = gravity;                                // Get the current gravity
     var shootScript        : PlayerShoot_JS = trans.GetComponent(PlayerShoot_JS);    // Get the shootScript
     var dyingParticles    : ParticleSystem;                            // The particles that will be instantiated when dying
 
     isAlive = false;                        // Prevent from moving the player
     trans.parent = null;                    // Set the transform back to worls, in case we were in the elevaator
     controller.enabled = false;                // Disable character controller
     shootScript.shootEnabled = false;        // Disable shooting
     rabyGeo.gameObject.SetActive(false);    // Deactivate geos
     gravity = 0;                            // Set gravity = 0, so we don't fall
     vertical$$anonymous$$ove = 0;                        // Disable horizontal movement
     dyingParticles = Instantiate(deadParticle, trans.position, Quaternion.identity);
 
     yield WaitForSeconds(1.5);                // Wait some time
 
     trans.position = checkPointPosition + Vector3.up;    // $$anonymous$$ove the character to the checkPoint position
     
     yield WaitForSeconds(0.5);                // Wait some time
 
     rabyGeo.gameObject.SetActive(true);        // Activate the character geos
     controller.enabled = true;                // Enable characterController
     gravity = curGravity;                    // Restore gravity
     isAlive = true;                            // Enable movement
     shootScript.shootEnabled = true;        // Enable Shooting
     
     dyingParticles.Clear();                        // Clear particle system
     dyingParticles.gameObject.SetActive(false);    // Disable the particle system
 }
avatar image instruct9r · Jul 07, 2014 at 10:17 PM 0
Share

Actually i just found, that the BackToCheckPoint(), stops the execution, when the bullet get's destroyed. But what the bullet have to do with the Function, that is attached to the player. It calls it and after that it get's destroyed :\

avatar image instruct9r · Jul 07, 2014 at 10:43 PM 0
Share

Aaand just realized, that if one object calls a function, that have yield and get's destroyed immediately, the function stops the execution at the yield.

It also happens if the object, that calls the function get's deactivated, the function also stops at the Yield.

So can somebody tell me how i can make a function that have Yield, continue working after the object, that calls the function get's deactivated...

avatar image
0

Answer by MaxLohMusic · Jan 29 at 10:14 PM

I had the same issue. I had two different classes, Player and Enemy, each with their own public variable "health". I found that the enemy somehow was using the player's health. Now I can't speak to whether another bug was a confounding factor; however I can say that after ONLY renaming the player's "health" variable to "playerHealth" using Visual Code refactoring tool doing NOTHING ELSE, everything worked correctly. This does not seem like correct behavior that a program's behavior can change from the way the variables are named!

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 Bunny83 · Jan 30 at 05:53 AM 0
Share

First of all this question is from 2014 and was about UnityScript (which was a javascript insprired language). So you most likely don't have the "same issue". Please do not necro post ancient questions with an answer that doesn't answer the question. If you have a question, please ask a question and present your actual case. UnityAnswers is not for discussions, that's what the Untiy forums are good for. US is for clear questions that can be answered.


Apart from all that, I highly doubt rena$$anonymous$$g a variable changes the behavior. It's more likely you may had some faulty serialized value which you lost by rena$$anonymous$$g the variable. Have you actually tried to rename the variable back to health? One class can not "somehow" use a variable from a different class. This makes absolutely no sense and is literally impossible unless you specifically access a variable on another object. However in that case there is nothing "strange" going on since you specifically did this. When a PC does "unpredictable" things it can only mean:

  • You do not fully understand what it actually does or you are missing important information.

  • it is actually physically broken

There are no other reasons. Note that the first point would includes software bugs as well However those are fully deter$$anonymous$$istic once you understand how it works. If PCs are not reliable they would be useless.

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

24 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

Related Questions

Yield function goes slow sometimes/differently? 2 Answers

Coroutoutine doesnt work properly. 3 Answers

problem with raycasting and functions 1 Answer

Stop the Update function so death animation can complete. 1 Answer

function OnTriggerEnter doesn't work 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