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
1
Question by Velastine · Mar 19, 2014 at 12:02 PM · editorbuilddictionaryexceptions

Runs fine in editor, tons of exceptions in build

I've built a game that runs fine in the editor. But once I play it in build (developer mode on), exceptions pop up.

By reading the output_log.txt in xxx_Data, I have tracked down the problem to my Dictionary for pool manager. I was putting pools into a pool manager for easy reference later.

The code looks something like this on the Pool.

 [SerializeField]
 String _name;
 void Awake() {
     Debug.Log("Name: "+_name);
     PoolManager.AddPool(_name, this);
 }


The _name is a unique identifier for the pool. For example, "Projectiles", "Debris" etc. Now here comes the fun part.

In the editor, the console displays:

 Name: Debris
 UnityEngine.Debug:Log(Object)
 Name: Projectiles
 UnityEngine.Debug:Log(Object)

In other words, absolutely no problem.

But in my build, the file logs the following:

 ...
 UnloadTime: 0.349474 ms
 Name: [SOH] // <------------------------ HERE!!!!
 UnityEngine.Debug:Internal_Log(Int32, String, Object)
 UnityEngine.Debug:Log(Object)
 Vst.Performance.PoolBase:Awake()
 ...

[SOH] is an ASCII character. Like [NUL] and other non-displayable characters. You'll know if you've used Notepad++ before.

So my build is actually, using [SOH] as a key to the Dictionary. What follows are catastrophic. When my Projectiles pool gets added, because Debris is already inside the dictionary with key [SOH], I first get ArgumentException, saying the key already exists.

Later, when my weapons start instantiating projectiles from the pool, I get TONS and TONS of KeyNotFoundException because the pool couldn't be added in the first place.

Since the Awake and Start of said objects are cut off midstream due to exceptions, they fail to instantiate properly, leading to TONS and TONS of NullReferenceException when the Update loop starts to run.

So can anyone tell me WHY this is happening to me?

A million thanks.

Vst.

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
Best Answer

Answer by Velastine · Mar 21, 2014 at 02:43 AM

It seems that I have discovered the reason why such tragedy happens.

Consider the following code, put in ONE file named TesterBase.cs.

 namespace SomeNamespace {
 
     public class TesterBase : MonoBehaviour { // provides access to raw type Tester<T>
         
         [SerializeField]
         int _number = 100; // just a simple number
         
         public int Number { get { return _number; } }
         
     }
     
     public class TesterBase<T> : TesterBase where T : class { // the class that will be inherited
         
         [SerializeField]
         T[] _objects;
         
         public T[] Objects { get { return _objects; } }
         
     }
     
 }

And in another file, namely SomeObject.cs:

 namespace SomeNamespace {
 
     public class SomeObject : TesterBase<String> {
         
         void Update() {
             Debug.Log("number: "+Number);
             Debug.Log("length: "+Objects.Length);
         }
         
     }
 
 }

This will work perfectly in the editor. I set _number to 10 and put hello and world as two strings in the Objects array. When played, the log repeatedly prints out:

 number: 10
 length: 2

So we are cool.

BUT in the build, the log first shows some weird errors saying:

 The file 'C:/.../xxx_Data/mainData' is corrupted! Remove it and launch unity again!
 [Position out of bounds! 1819058236 > 15076]

Sometimes the Objects array can be instantiated properly and does not return null. But the length is definitely wrong (5 is printed in my case). For _number, the value can be quite random (I got 2).

TO FIX IT, the non-generic base class and generic base class (`TesterBase` and TesterBase respectively) should not share the same name.

Comment
Add comment · 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
0

Answer by wildex999 · Mar 19, 2014 at 12:45 PM

The only thing I can think of is that something is called in a different order when running trough the build. Maybe it's just been luck that _name has been set in the editor so far.

Take a look at where you set _name and see if it's called before you use _name.

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 Velastine · Mar 19, 2014 at 02:14 PM 0
Share

Forgot to say that _name is a serialized field (edited in question). Can we be sure it is set when Awake is called?

 public class Pool : $$anonymous$$onoBehaviour {
     [SerializeField]
     String _name;
     void Awake() {
         Pool$$anonymous$$anager.AddPool(_name, this);
     }
 }

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

22 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

Related Questions

Distribute terrain in zones 3 Answers

Standalone build doesn't create gameobjects properly 1 Answer

Create custom warning dialog on build, if a script or gameobject exists in the scene 2 Answers

OnServerStart not being called in standalone build. Works in editor. 1 Answer

how to remove the unity_editor define in web player 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