Forum rules - please read before posting.

Change Hotspot name in code and show it in the hotspot Menu

Hi Chris!

I want to update the name of a hotspot in code, during gameplay.

Updating the name of the hotspot and even its AltLabel was easy enough, but the thing is the Hotspot Menu that shows the names of clicked hotspots doesn't seem to care about changes made to the hotspot's name. It just shows the name the hotspot had by default, even though I can see in the editor that the name of the hotspot has now changed.

I have tried:
this.name  = "New name";   on the gameObject containing the hotspot

And this: 
this.GetComponent<AC.Hotspot>().SetName("New name", this.GetComponent<AC.Hotspot>().lineID);

Any ideas? 



Comments

  • SetName () should work, but try passing -1 as the second parameter.  Technically you're supposed to pass an ID generated by SpeechManager, so that the Hotspot's new name will be translated as well.

    This is what the Hotspot: Rename Action does.
  • No luck.

    I have a GameObject with the hotspot script attached, and a Unity Text component, and the following script.

    In the Text component I write 'This is your partner!' , and link it in the editor to this script: 

    (the logic is in Update() for now, I know):

    //
    public class PlayerFirstNameSetter : MonoBehaviour {

    public Text defaultPlayerName; 

    void Update()
    {
    AC.Hotspot HS = this.GetComponent<AC.Hotspot>();
    HS.SetName(defaultPlayerName.text, -1);
    }
    }
    //

    I can see the hotspot's Label in the Editor changing, menaing it does get the correct string from the Text component, and the .SetName() is doing its job. But still when I click it... it shows the old name of the Game Object. 
  • It's not clear if it's your code or the Hotspot.  Try doing this with the Hotspot: Rename Action and see if that works.  If you aren't using the original language, then that could also be a problem.
  • Ah. Yes. That's the problem.

    I have the speechmanager set to 'prevent original language' because we have a couple different languages.

    Any thought on how to dynamically change a Hotspot's name during gameplay in the case of multiple translations? 
  • The thing is, our game is going to get a player's first name from a server.

    So what I am looking to do here is have a default hotspot name setup in all supported languages, but have that default name overwritten when we get a player's real name from the server.


  • I see.  There's an issue with Hotspot's GetName function that will cause the gameobject's name to be returned if a translation request fails.  I will fix it officially in the next release, but this is the corrected code if you want to make it:

    public string GetName (int languageNumber)
    {
      string newName = gameObject.name;
      if (hotspotName != "")
      {
        newName = hotspotName;
      }

      if (languageNumber > 0)
      {
        return SpeechManager.GetTranslation (newName, displayLineID, languageNumber);
      }

      return newName;
    }

    You'll then need to manually override the new name's lineID, because passing -1 to the SetName function actually prevents it being overwritten as a safeguard.  Once you've amended the function above, run this after calling SetName:

    myHotspot.displayLineID = -1;
  • Thanks! Will have that implemented :) 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.