- Home /
Not updating when script value is changed by an editor script
I have an editor script that generates text based on a prefab created with SpriteText. My script successfully builds the instances of the SpriteText, but the objects are not updating for the new text string assigned programmatically.
// Executed within OnInspectorGUI var clone : GameObject = EditorUtility.InstantiatePrefab(target.WordPrefab); clone.name = ""+index+"_"+p; clone.transform.parent = words.transform;
var spriteText : SpriteText = clone.GetComponentInChildren(typeof(SpriteText)); spriteText.text = p; // assigning new text string
// trying to force an update EditorUtility.SetDirty(spriteText); EditorUtility.SetDirty(clone); spriteText.UpdateMesh();
spriteText.SendMessage("Update");
When this code is executed, I get the new prefab instances, but they all appear with the default prefab text, despite that when I look at the inspector for each item they have been assigned the new text correctly. If I manually change the text, it then will finally update, but I can't seem to trigger an update from my editor script. The calls to UpdateMesh() and SendMessage() are simply my feeble attempts, but no luck.
Any ideas to force the script/object to update?
Answer by mstultz · Feb 11, 2011 at 05:59 PM
Are you applying [ExecuteInEditMode] on the SpriteText GameObject?
I didn't make any changes to the any of the the SpriteText code.
Your answer
Follow this Question
Related Questions
Only run the function once 2 Answers
Select sprite preview images not showing after upgrading to 2020.2.2f1 3 Answers
Drop down with sizes 1 Answer
Variable creation through Inspector using CustomEditor? 1 Answer
Dynamically update the editor? 3 Answers