Search Unity

Localization Tools -Help

Discussion in 'Community Learning & Teaching' started by TheYumma, Mar 26, 2017.

  1. TheYumma

    TheYumma

    Joined:
    Jun 25, 2016
    Posts:
    3
    So after taking a break from Unity I decided to get back by localizing my game.

    Anyhow , everything went smoothly until the 7.Localized Text Component Video.

    I get the following Error:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. LocalizedText.Start () (at Assets/Scripts/LocalizedText.cs:41)
    in :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class LocalizedText : MonoBehaviour
    7. {
    8.  
    9.     public string key;
    10.     private string value;
    11.  
    12.     public Text textObjectToLocalize;//Drag the text here in the Editor
    13.  
    14.     // Use this for initialization
    15.     void Start()
    16.     {
    17.         /*
    18.          * Text Object Attached
    19.          */
    20.  
    21.         Text text =GetComponent<Text>();
    22.         if (text != null)
    23.         {
    24.             Debug.Log(gameObject + " has text: " + text.name + " key:" + key);
    25.             if (LocalizationManager.instance != null)
    26.             {
    27.                 value = LocalizationManager.instance.GetLocalizedValue(key);
    28.                 text.text = value;
    29.             }
    30.             else
    31.             {
    32.                 text.text = "Error";
    33.             }
    34.         }
    35.         //The dragged Text Object
    36.         else
    37.         {
    38.  
    39.             if (LocalizationManager.instance != null) {
    40.                 value = LocalizationManager.instance.GetLocalizedValue(key);
    41.                 textObjectToLocalize.text = value;
    42.                 }
    43.             else
    44.             {
    45.                 textObjectToLocalize.text = "Error";
    46.             }
    47.         }
    48.      
    49.            
    50.     }
    51.  
    52. }
    I modified the original code because the same error happened, I tried checking if there's an Object attached and there is .I also made sure I attached the script correctly to a Text Object , but the error keeps poping up. Even though the other language was being translated and the text.text is being changed in the Game tap.
    This is the original co:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. public class LocalizedText : MonoBehaviour {
    8.  
    9.     public string key;
    10.  
    11.     // Use this for initialization
    12.     void Start ()
    13.     {
    14.         Text text = GetComponent<Text> ();
    15.         text.text = LocalizationManager.instance.GetLocalizedValue (key);
    16.     }
    17.  
    18. }
    Thanks in advance I spent hours trying everything I could think of .
    this is the tutorial btw https://unity3d.com/learn/tutorials/topics/scripting/localized-text-component?playlist=17117
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,610
    I think it refers to this line, so you should make sure "textObjectToLocalize" and "value" both are non null.

    Place a debug line just above the line with error, and print to the console the value of those vars, see what comes up.

    Edit: sometimes it will look on the forums like it's one line, but in your ide it might be another line number, so if it's not that line, or those values aren't null, check other nearby values.
     
    TheYumma likes this.
  3. TheYumma

    TheYumma

    Joined:
    Jun 25, 2016
    Posts:
    3
    I placed it and I can see that the functions that returns the translated text to the first attached Text Object with no problems :
    Code (CSharp):
    1. text.text=value;
    when then it also goes to this Text Object that I dropped in the Editor
    Code (CSharp):
    1. textObjectToLocalize.text = value;
    this is where the problem is , I'm sure I dropped the Text in the Editor so I dont understand the problem is.

    I tried removing the whole block where I'm initializing textObjectToLocalize , and somehow the error didn't show up in the previous block ( as I mentioned before I faced the same error in the original code).

    I'll have to search further and see if it has anything to do with not being connected to Unity services or something else.
    thanks consider it closed.

    also thanks for the forum tip.
     
    MD_Reptile likes this.
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,610
    No problem, good luck!
     
  5. unity_aTIog3vJzk9cXw

    unity_aTIog3vJzk9cXw

    Joined:
    Nov 25, 2019
    Posts:
    1
    Hey, did you already find a solution for this problem? I'm still stuck :'(
     
  6. elitglad

    elitglad

    Joined:
    Feb 16, 2020
    Posts:
    4
    I think it refers to this line, so you should make sure "textObjectToLocalize" and "value" both are non null.



    _____________________________________________________
    Sarkari Result Pnr Status 192.168.1.1
     
    Last edited: Feb 17, 2020
unityunity