• 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 /
This question was closed Jul 28, 2022 at 07:30 PM by Bishmanrock for the following reason:

The question is answered, answer documented

avatar image
Question by Bishmanrock · Jul 28, 2022 at 07:15 PM · buildbuild-errorissueissuesbuilds

Discrepancies Between Build and Editor

Hi, I've finally reached a point where I've been able to do a build of my game, but upon building and running I'm finding some game breaking discrepancies between the editor and the build.

I've checked articles on here which suggest the run order could be different, but I'm struggling to see how that's relevant to this instance, so I think something else might be going on. There's a lot of interweaving scripts, so I'll try and just mention the most relevant parts

Firstly, the issues in the build are that when I boot the game, many of the enemies on the level are already dead. In the editor version, all of them spawn with full health and act normally, but in the build several spawn immediately dead. It is always the same ones that spawn dead. I have rebuilt several times with changes and the order does not change. The ones that spawn alive also always spawn alive.

Note all the enemies use the exact same prefab. I have checked and there is no difference in settings between them in the Scene.

To try and keep this brief, my system uses a D&D style RPG stats system. The enemies (and players) health is generated using the following:

maxHealth = (attributes.constitution + attributes.size) / 2;
currentHealth = maxHealth;

(Attributes is a script attached to the same object that stores their stats. Because the script is always contained on the same object, this is why I don't believe it's a run order issue).

If I remove the above code and replace it with a test of currentHealth = 25 to test, all enemies spawn alive and well without issue.

I added some lines to the Debug.Log to confirm what's happening in the build. It prints when generating the health, and also when the enemies dies. I get the following for all enemies:

Alien (11)max health is 25.
Alien (11)current health before gen is 25.
Alien (11)current health after gen is 25.
Alien (11) has been killed.

So it's generating the max health correct, setting the current health correctly, and then... killing the enemy. But I'm not sure why. And again, this behaviour is not apparent in the editor - the game runs as intended. I can also see other examples where they spawn, set the health, and then don't die.

I don't expect anyone to wrap their head around my code (which I've only posted parts of here as an example), but could anyone give me an idea of what exactly I should be looking for? I'm completely stumped and have no idea how to continue troubleshooting this. At first I wondered if it was something to do with my build settings, but I can't make heads or tails of the logic of which some enemies are fine and others are broken.

I can post more code if needed but wanted to keep it light as I'm not convinced that's the core issue.

Thank you!

EDIT: It is the run order. I've just added more debugging logs to the code, and the health check is happening before the Constitution and Size rolls are being done, hence why health is returning as a 0.

EDIT2: Can confirm that by putting the stat generation into the Awake function, and the stat checks into the Start, I've forced everything to trigger in the correct order now. Just goes to show sometimes you just need to write things out! Will close this ticket now but leave here for reference for others.

tl;dr - use Debug.Log to make sure any data dependencies are being generated in the correct order. Don't take script order exaction for granted!

Comment

People who like this

0 Show 0
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

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

154 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 avatar image avatar image avatar image avatar image

Related Questions

Seems to build, shows the following errors 2 Answers

Issues When Building the Game for any Platforms 1 Answer

App not installed on android because keystore 0 Answers

Error building Player: Win32Exception 1 Answer

Build error 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