Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
This question was closed Apr 05, 2016 at 11:43 PM by haskell33 for the following reason:

I Found what the problem was... I was actually turning the shootTrigger to false inside another class. Problem solved.

avatar image
0
Question by haskell33 · Apr 05, 2016 at 08:28 PM · updateinheritancederived-classscript execution order

Script execution order of child and parent classes - Parent then children???

HI there. I have a parent class called Weapon(), which is non-instantiable. NormalWeapon() derives from it. Only NormalWeapon has charge. The code is this:

 Weapon Update():
 if (shootTrigger == true) 
     shootTrigger = false;
 else if (InputController.GetKeyDown (Buttons.shoot)) 
     shootTrigger = true;

That is, I want shootTrigger to be true only for a frame and NormalWeapon to get this info, so in NormalWeapon Update() we have:

 if (shootTrigger) 
     charging = true;

"charging" never happened to be true. So in Script Execution Order I put:

Weapon (100)

NormalWeapon (200)

Still, charging never happened to be true. NormalWeapon's charging gets the true value only if I put the shootTrigger verification in NormalWeapon's LateUpdate().

The impression I'm getting is this: parent Update() executes then children Update() executes Even if this order is changed in the Project Settings???

Thank you!

Comment
Add comment · Show 1
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 Downstream · Apr 05, 2016 at 08:45 PM 0
Share

@haskell33 I believe script execution order is only helpful with start and awake methods, etc. not updates. That is so you can run scripts that do initialization, say something that loads data, before any other script that depends on the data being loaded runs.

1 Reply

  • Sort: 
avatar image
2

Answer by b1gry4n · Apr 05, 2016 at 08:42 PM

You could just call a virtual function instead of trying to balance between false and true and getting mixed up.

Your "NormalWeapon" script derives from "Weapon" correct? Meaning the top of your NormalWeapon script it looks like this?

 public class NormalWeapon : Weapon {

Why not just do this in weapon:

 public class Weapon : MonoBehaviour {
 
     bool shootTrigger = false;
     void Update()
     {
         if (InputController.GetKeyDown(Buttons.shoot) && !shootTrigger) {
             shootTrigger = true;
             Shoot();
         }            
     }
 
     public virtual void Shoot()
     {
 
     }
 }


and in your normal weapon script...

 public class  NormalWeapon: Weapon {
     bool charge = false;
     public override void Shoot()
     {
         charge = true;
         shootTrigger = false;
     }
 }


Another thing too...GetButtonUp might work better for you. If you want the user to have to click each time shootTrigger = true, GetButtonUp waits until the button has been lifted. A button has 3 states... GetButton (called every frame the button is being held), GetButtonDown (Called the frame when the button is pressed) and GetButtonUp (called when the button is lifted). These have an order of their own by the nature of how a user is clicking the physical button, be it a key on a keyboard, mouse, touchscreen, nuclear missile launch button.

GetButtonDown -> GetButton -> GetButtonUp

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 haskell33 · Apr 05, 2016 at 11:04 PM 0
Share

Your code is way more elegant than $$anonymous$$e, I'll end up s$$anonymous$$ling that for myself lol Thanks!

About the GetButtonUp, yeah I'm using that already so that "charging" can get set to false, I'll probably get rid of this shootTrigger variable (didn't know why I came up with this in first place lol).

About the script execution order, that's still a mystery to me. Regarding this particular situation, that is. I get that your code solution will always work, but I'm still curious about why setting the Script Execution Order in Project Settings didn't work for me. And I should correct myself about the last statement: "The impression I'm getting is this: parent Update() executes then children Update() executes Even if this order is changed in the Project Settings???" If this was actually true, the execution order would be Weapon => Normal Weapon => Weapon => Normal Weapon etc. just like I wanted it to be. What I'm actually getting is Weapon => Weapon => Normal Weapon => Normal Weapon etc. Weird...

Follow this Question

Answers Answers and Comments

41 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 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

Get reference to dynamically added script 1 Answer

Object Reference to a global private variable is set in Awake function but lost in another function in the same class. 0 Answers

[SOLVED] JSON Serialization of Derived Classes 2 Answers

Define attacks to choose from 1 Answer

[VIDEO] Animator controller stopping physics? inheritance problem or bug? 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