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 Hikaru-Diamond · Nov 07, 2021 at 11:34 PM · bugscriptable objectmonobehavior

1 of the 2 GameObjects with the same MonoBehavior script somehow ignores an If conditional?

Programming a Turn-Based RPG in which for normal attacks a character can strike for X amount of times depending on their Level.

A CharacterManager script handles that part of the calculation with the following code, which works perfectly.

 // Called at Start of CharacterManager only if the Manager has a ScriptableObject with the Character' Data for their Stats and stored Skills.
     private void SetData() {
    // Every Stat calculator according to Level and Base proficiency of the character's data.
     
     // NAHits "translates" to Natural Hits according to their level.
     // Ceiling to the nearest integer so that even if the character is Level 1 it will
     NAHits = Mathf.CeilToInt(Level / 10f);
     
     }

From there each Command, like Attack in this case, has the following class, CommandManager, that manages each individual Command with a ScriptableObject of CommandData that contains the metadata of each command, from type to even number of hits if it is an Attack type of command.

 private int intHits;
 
     public void Start()
     {
 
         if (commandData)
         {
             
             if (commandData.intStrikes > 0)
             {
                 // If CommandData reads that it has more than 0 strikes then CommandManager's Hits
                 // will have the CommandData's numbrer of strikes.

                 intHits = commandData.intStrikes;
             }
             else
             {
                 // If CommandData reads 0 or less strikes then CommandManager
                 // will read Natural Hits from it's owner with a CharacterManager script,
                 // which depend on the Character's Level.

                 intHits = CommandOwner.NAHits;
             }
 
             Debug.Log("Action registered strikes : " + this.intHits + " for " + CommandOwner.charID);
         }
     }


In this situation, 2 playable characters of Level 40 have a generic Attack command with a CommandManager, which reads from the same generic (intended to be used across all Playable Characters) ScriptableObject CommandData named Attack with 0 intStrikes.

alt text

PC1 manages to get the expected behavior to work, in which PC1's Attack command will have 4 hits (40/10 = 4, thus 4 hits).

PC2, however, doesn't behave as expected and even though its Attack command has the same generic CommandData as PC1's Attack command with 0 intStrikes (which should make PC2's CommandManager for regular Attack have 4 hits, it instead has 0 hits), as seen in the Console's Log.

alt text

I have not been able to identify the reason for this oddly specific bug, but I hope that this can have an explanation and a fix.

attackdata.png (49.7 kB)
debug-log-attack-command-0.png (30.1 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

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

Missing Monobehavior after switched OS from Windows to Mac 1 Answer

Fix for strange black squares over trees when using blur? 4 Answers

when pressing play gameobject get deleted and the game breaks 0 Answers

Object Rotating Randomly 1 Answer

Why do I keep getting UNetWeaver error: GetWriteFunc recursion depth exceeded for NetworkInstanceId 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