• Hi Guest!

    This is a notice regarding recent upgrades to the Hub. Over the last month, we have added several new features to improve your experience.
    You can check out the details in our official announcement!

How change text in Button on scene into script?

MaxToMax333

New member
Messages
13
Reactions
3
Points
3
Please tell me, what am I doing wrong?
I need change text button into script. The text of the button on the scene changes, but there is no button in the settings.

C#:
const string uiButtonName = "Pink";
Atom uiButtonAtom = SuperController.singleton.GetAtomByUid(uiButtonName);
if(uiButtonAtom == null || uiButtonAtom.type != "UIButton")
{
  SuperController.LogError($"No UIButton atom found with name '{uiButtonName}'");
  return;
}
// The transform which contains the clickable button component in the UIButton atom's gameobject hierarchy
Transform buttonTransform = uiButtonAtom.transform.Find("reParentObject/object/rescaleObject/Canvas/Button");
if(buttonTransform == null)
{
  SuperController.LogError($"Could not find the button transform of UIButton '{uiButtonName}'");
  return;
}
var txt = buttonTransform.GetComponentInChildren<Text>();
txt.text = "new name";

ChangeTextButton.png
 
Last edited:
Please use code block formatting to make the code more readable :)

1716749807440.png


You might want to go to the official VAM discord's #scripting channel if you have a lot of scripting questions. There's also lots of good info there (questions and answers that have been asked before).

As to your question, the button text field is a triggerable parameter that you can find with the methods that are available for finding triggerable parameters on atoms and their storables.

C#:
var atom = ...
var storable = atom.GetStorableById("Text");
var textParam = storable.GetStringJSONParam("text");
textParam.val = "NewButtonText";

This is equivalent to calling the following trigger action

1716750100527.png
 
Back
Top Bottom