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 Naim · Apr 30, 2011 at 10:22 AM · stringsingletoncreationtable

StringTable manager singleton creation

I'm attempting to create a StringTableMgr class that will load and keep track of string tables, but since it has to be globally accessible, I'm looking at this:

http://forum.unity3d.com/threads/35617-TextManager-Localization-Script

to see how to create a script that can be globally accessed without having to have an instance in each game object.

My problem is that when I do it in the same way as the article I get a "You are not allowed to call Internal_CreateGameObject when declaring a variable" error.

public class StringTableMgr : MonoBehaviour { public class StringTable { // blah, unrelated }

 static StringTableMgr m_StringTableMgr;
 List<StringTable> m_StringTableList;

 private static StringTableMgr Instance 
 {
     get
     {
         if (m_StringTableMgr == null) 
         {
             GameObject notificationObject = new GameObject("StringTableMgr");

             m_StringTableMgr = (StringTableMgr) notificationObject.AddComponent(typeof(StringTableMgr));

             m_StringTableMgr.m_StringTableList = new List<StringTable>();
         }
         return m_StringTableMgr;
     }
 }

 public static StringTableMgr GetInstance()
 {
     return Instance;
 }   

 void Awake()
 {
     GetInstance();
 }   

 public static bool LoadStringTable(string stringTableName)
 {
     StringTableMgr stringTableMgr = GetInstance();

     foreach(StringTable table in stringTableMgr.m_StringTableList)
     {

     }

     // blah
 }

}

I get the error on the line at the top where I create the GameObject. If I leave the creation code, and reference the 'm_StringTableMgr' var directly, I get an null reference exception on the 'foreach' statement in LoadStringTable, which could be either the StringTableMgr var or the 'm_StringTableList'

I don't know what I'm doing wrong, since I'm fairly certain if this code were to run, it would work, since by calling GetInstance() in the Awake() function, I'm basically assuring the creation of the StringTableMgr object and it's data structures.

Can anyone see anything that I've missed, or think of something that I should know but don't?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by yoyo · May 01, 2011 at 12:49 AM

Since you're creating this in script anyway, just remove the ": MonoBehaviour" from the class -- make it a regular class, not a component.

Comment
Add comment · Show 2 · 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 Naim · May 01, 2011 at 11:01 AM 0
Share

Okay, that's fixed part of it, but I'm loading a text asset using Resources.Load and then using a StringReader to parse the text from it, and it's giving me a "You are not allowed to call get_text when declaring a variable".

Is there some problem using Resources.Load from outside of a Unity script?

avatar image yoyo · May 02, 2011 at 05:04 AM 0
Share

Sounds like a new issue -- maybe ask it as a new question, and include some of your code? Resources.Load should be callable from anywhere.

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

No one has followed this question yet.

Related Questions

calculate terms in runtime 3 Answers

Calling a script with name 2 Answers

String split script 1 Answer

Accessing a function through its name stored in a string JS 2 Answers

HealthPack Script Problem... 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