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 JNetRocks1316 · Feb 25, 2014 at 05:18 AM · updatestopped

Update Stopped Working

Updated with scripts, sorry it's long, I don't know what's causing the issue, so figured I'd include it all.

  • Yes I have looked through the forums!
    • My console messages ARE expanded

    • I have Debug.Log("Test") in Update, it is NEVER called

    • The Update was working fine for a few hours, then just stopped.

    • I deleted everything else in the Update and just tried it with the Debug.Log and it does nothing.

Are there any ever exceptions that would cause Update to not work? The only thing I can think of is that this is a base class (Creatures.cs, and then there's another class that uses this as the 'base' class (sorry not a programmer, so technical terms might be off)).

Base Class

 using UnityEngine;
 using System.Collections;
 
 public class Creature : MonoBehaviour {
 
     //Variables Hidden

 
     void Awake(){
         //burningFX = GameObject.Find (this.transform.name + "/CondiFX_Burning");
         burningFX = transform.Find("CondiFX_Burning").gameObject as GameObject;
         chilledFX = transform.Find ("CondiFX_Chilled").gameObject as GameObject;
         poisonedFX = transform.Find ("CondiFX_Poisoned").gameObject as GameObject;
         bleedingFX = transform.Find ("CondiFX_Bleeding").gameObject as GameObject;
 
     }
 
 
     void Update(){
         Debug.Log ("Updaaaate");  //This isn't called!
 
         if (burningTime > 0.01f){
             burningTime -= Time.deltaTime;
         } else if (burningTime <= 0.01f){
             burningTime = 0f;
             burningFX.SetActive (false);
             CancelInvoke("ApplyBurning");
         }
         
         if (chilledTime > 0.01f){
             chilledTime -= Time.deltaTime;
         } else if (chilledTime <= 0.01f){
             chilledTime = 0f;
             chilledFX.SetActive (false);
             CancelInvoke("ApplyChilled");
         }
         
         if (poisonedTime > 0.01f){
             Debug.Log ("7:  Poison has time on it");
             poisonedTime -= Time.deltaTime;
         } else if (poisonedTime <= 0.01f){
             poisonedTime = 0f;
             poisonedFX.SetActive (false);
             CancelInvoke("ApplyPoisoned");
         }
         
         if(bleedingTime > 0.01f){
             bleedingTime -= Time.deltaTime;
         } else if(bleedingTime <= 0.01f){
             bleedingTime = 0f;
             bleedingFX.SetActive (false);
             CancelInvoke("ApplyBleeding");
         }
     }
 
     //Called to add or remove health from the current health total
     public void AdjustCurHP(float healthAdjustment){
         if(curHP > 0)
             curHP += healthAdjustment;
     }
 
     //Apply Conditions, requires a condition and duration parameter.  Sets total condition time to += duration and activates the visual FX
     public void ApplyCondition(string condition, float duration){
         if(condition == "burning"){
             burningTime += duration;
             burningFX.SetActive(true);
 
             if(!IsInvoking("ApplyBurning"))
                 InvokeRepeating("ApplyBurning", 0f, 1f);
         } else if (condition == "chilled"){
             chilledTime += duration;
             chilledFX.SetActive(true);
 
             if(!IsInvoking("ApplyChilled"))
                 InvokeRepeating("ApplyChilled", 0f, 1f);
         } else if (condition == "poisoned"){
             poisonedTime += duration;
             poisonedFX.SetActive(true);
 
             if(!IsInvoking("ApplyPoisoned"))
                 InvokeRepeating("ApplyPoisoned", 0f, 1f);
         } else if (condition == "bleeding"){
             bleedingTime += duration;
             bleedingFX.SetActive (true);
 
             if(!IsInvoking("ApplyBleeding"))
                 InvokeRepeating("ApplyBleeding", 0f, 1f);
         }
     }
 
     //Invoked to repeat damage at tick intervals
     void ApplyBurning(){
         AdjustCurHP(-burningDMG);
     }
 
     void ApplyChilled(){
         AdjustCurHP(-chilledDMG);
     }
 
     void ApplyPoisoned(){
         AdjustCurHP(-poisonedDMG);
     }
 
     void ApplyBleeding(){
         AdjustCurHP(-bleedingDMG);
     }
     
 }


Inherited Class

 using UnityEngine;
 using System.Collections;
 
 public class SnowStatus : Creature {
 
     private float guiHPBarLength = 0f;
     private float screenH = 0;
     private float screenW = 0;
     
     private bool dead = false;
     
     void Start(){
         guiHPBarLength = ((Screen.width/2) * (curHP/maxHP));
         screenW = Screen.width;
         screenH = Screen.height;
     }
 
     void Update(){
         if (curHP > 0){
             guiHPBarLength = ((Screen.width / 2) * (curHP / maxHP));
         } else {
             guiHPBarLength = 0;
             Death();
         }
     }
 
     void Death(){
         SnowTPCon snowController = this.GetComponent ("SnowTPCon") as SnowTPCon;
         SnowTPCam snowCam = Camera.main.GetComponent ("SnowTPCam") as SnowTPCam;
         snowController.charControlled = false;
         snowCam.camFreeze = true;
         dead = true;
     }
Comment
Add comment · Show 6
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 robertbu · Feb 25, 2014 at 05:45 AM 0
Share

Is your game object the script attached to disabled? Since this is the base class, is this class derived from $$anonymous$$onobehaviour? Providing your script...even if it is just a few lines long...may be helpful in figuring out what is going on.

avatar image JNetRocks1316 · Feb 25, 2014 at 06:22 AM 0
Share

Sorry about not having the script. I added it now. The game object is definitely enabled. Other variables are being modified from other methods, just the Update is not working.

avatar image deltamish · Feb 25, 2014 at 06:24 AM 0
Share

are both scripts attached to same object

avatar image JNetRocks1316 · Feb 25, 2014 at 06:25 AM 0
Share

No, just the Inherited class is attached to the game Object.

avatar image JNetRocks1316 · Feb 25, 2014 at 06:41 AM 1
Share

Nice, thank you! :) Excited to learn some new things. I haven't worked with inherited classes before, so this is a learning experience!

Show more comments

1 Reply

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

Answer by deltamish · Feb 25, 2014 at 05:47 AM

Ahh. Since you are inherting a class other than monobehavior Update doesnt get called

MonoBehaviour calls the update function so you might wanna inherit fom that

If you have no idea what i am talking about

please do post your script

EG

 public class Class1:BaseClass // as you can seee it is inheriting from Base calss
 {
 
   void Update() //Does not get called
 {
 
 }
 }


Using Mono as base class

  public class Class1:MonoBehaviour // as you can seee it is inheriting from Moni class
     {
     
       void Update() //Does get called
     {
     
     }
     }

Base Class

  public class BaseClass:MonoBehaviour // as you can seee it is inheriting from Base calss
     {
       public string MyName;
       public virtual void MyUpdate() //Changes the name from Update to MyUpdate for better Understanding the realtionship
     {
      Debug.Log("Hello" + MyName);
     }
     }

Okay as you can see that Class1 is inheriting from Base Class For now Think of Inheriting as Using as in terms of using varialbes in Parent class (in this case Base class)

Now if you attach the Class1 to game Object Class1 can acess all methods and variables of BaseClass.

So what you could do is

Class1

 public class Class1:BaseClass // as you can seee it is inheriting from Base calss
 {
 
 public Class1
 :
  MyName = " Bill Gates "; // As you can see you can acess the variable from Base Calss 
 
 // Now lets call the Methoid of Base calss as you can see her you can directly acees the function 
 
 MyUpdate();
 }
 
 void Start()
 {
 // Here you need to base.MyUpdate
  base.MyUpdate();
 }
 }

Hope You understood What i am trying to explain.If you have any doubts just ask.

Comment
Add comment · Show 5 · 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 JNetRocks1316 · Feb 25, 2014 at 06:13 AM 0
Share

What's happening to $$anonymous$$e is opposite.

Base Class (Creatures : $$anonymous$$onoBehaviour) is the update that isn't working and (Player : Creature) IS working.

Let me update my question with some code, maybe that will help!

avatar image robertbu · Feb 25, 2014 at 06:37 AM 0
Share

If you want to do it by hand, you can call the base class Update() from the inherited class.

avatar image JNetRocks1316 · Feb 25, 2014 at 06:41 AM 0
Share

Robertbu - It seems that if your base class and inherited class both have Updates, then the inherited class overrides the base class.

If just your base class has it then your inherited class automatically runs the base class Update.

avatar image JNetRocks1316 · Feb 25, 2014 at 06:50 AM 1
Share

Everything makes sense, just a question on the last part.

     void Start(){
         base.$$anonymous$$yUpdate();
     }

For this part, base is referring to the base class, I'm assu$$anonymous$$g, and $$anonymous$$yUpdate means it 'grabs' the update from that base class.

Could I then extend the Update in the Inherited class, or is it only able to copy directly the base Update?

Going to do some research on this so I know better as well. I really appreciate the help!

avatar image deltamish · Feb 25, 2014 at 06:59 AM 0
Share

Sorry i gues i wasmt clear. Here base doesnt refer to Base Class It Just refers to the Parent Class. Lets Say the ParentClass is $$anonymous$$yNewParentClass and it has a function called GetInfo

Then in the iherited script you could acess it by using

base.GetInfo();

Could I then extend the Update in the Inherited class, or is it only able to copy directly the base Update?

Yes of cource you can extend your Update Function in order to call the prent class method you have to use base.Update(); or base.Start(); for Start like that

If you have further doubts post them here i will lokk into it once i get back

  • am gonna Leave now.Need to study *

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

20 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

Related Questions

Script wait for 3 seconds before running - stops it working altogether 2 Answers

Is there a yield WaitForSeconds type code for the update? 2 Answers

Problem with animation and void fixedupdate() 1 Answer

My Script Won't Update 1 Answer

How should I go about structuring a finite state machine if I need to make use of all three update functions? 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