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
1
Question by alienbaby · Dec 04, 2013 at 04:12 PM ·

3D TextMesh not updating on .text change

Hi,

I've read a few answers that seem related to this, but the answer I see given a lot is not working for me.

I have a script that declares a var of type TextMesh (I have also done this with a var od type GameComponent, and then used GetComponent to get a reference to the TextMesh, but the problem remains)

When I update the TextMesh by setting the .text field to a new value, it does not update at runtime. However, once I stop the scene from running the text is updated within the editor!

I have seen references to issuing .Commit(), but I believe that is for 2d work? - TextMesh does not have a .Commit() method.

The only answers I can find on the net just say to update TextMesh.text . For me, that doesn't work - the mesh is not updated in the game, but it is in the editor. Windows 7 (I've seen one reference to a bug in Android that has a similar behaviour)

Does anyone know whats going on?

Comment
Add comment · Show 3
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 KiraSensei · Dec 04, 2013 at 04:46 PM 0
Share

Could you post your script please ?

avatar image Owen-Reynolds · Dec 04, 2013 at 05:21 PM 0
Share

Yes -- sounds like a code thing. Like transform.Text$$anonymous$$esh isn't a shortcut (have to use transform.GetComponenent(). And in javascript it won't even give an error -- just won't do anything.

Commit is a whole unrelated thing. I've used lots of Text$$anonymous$$eshes, on iPads, and had all sorts of funny things (like s's tucking close up under the T's in some fonts,) but never had them not change.

avatar image alienbaby · Dec 04, 2013 at 07:53 PM 0
Share

The script in question;

 //Generate Score
 var tm:Text$$anonymous$$esh=prefabScoreText.GetComponent(Text$$anonymous$$esh);
 var score:int=parseInt(tm.text);
 tm.text=(score+10).ToString();

Where prefabScoreText is a 3D Text object prefab dragged into the script slot (the 'live' instance of the 3D text prefab is dragged from the same prefab and made a child of the camera in the scene, positioned so it is visible in the camera view when playing)

 var prefabScoreText: GameObject;


I have also tried making the slot a Text$$anonymous$$esh type, and dragging in the prefab;

 var prefabScoreText: Text$$anonymous$$esh;

And changing the setting code appropriatley (IE, remove the GetComponent and work with the prefabScoreText.text directly) But no joy.

The weird thing is, during runtime the rendered text does not change, but on returning to the editor the text has changed! (IE: the 3D text is attached to camera so it is in view. Before starting the game the camera view shows a big fat 0. after the game, it shows say, 160 - but in game it never changed from 0)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Owen-Reynolds · Dec 04, 2013 at 11:42 PM

You are probably changing the Asset (the real prefab, in Project) and not the actual gameObject. When you click on script variable prefabScoreText in the Inspector, Unity should be pulsing the scoreText in the scene.

In general, if you plan to run Instantiate, the link should go to the "real" prefab, from the Project folder. If you plan to change values, the link should be to an already made object (and you almost never Instantiate and change the same thing.)

The terminology is a little confusing. The Asset, in the Project folder is the real prefab. When you drag it into a scene, you might refer to the new object as a "prefab chair." But, during play, it's just a regular gameObject. The magic link to the prefab is only to help during editing (which is why you aren't seeing your real score change.)

Comment
Add comment · Show 4 · 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 alienbaby · Dec 06, 2013 at 02:45 PM 0
Share

Ahh ok. I knew it was something along these lines just couldn't puzzle it out.

So, for the 3DText object, I have to instantiate that and child it to the camera at runtime? - because it's not possible to drag an instance from the scene hierarchy to the script slot - or am I missing something there?.

avatar image KiraSensei · Dec 06, 2013 at 02:47 PM 0
Share

Yes you can drag and drop a game object from the scene hierarchy to the inspector and you don't need to instantiate it to correctly modify your object. But if you drag and drop a prefab, you need to instantiate it before changing something in it.

avatar image Owen-Reynolds · Dec 06, 2013 at 03:19 PM 0
Share

The only "can't drag" rule is you can't drag an instance from the scene into a script slot of a prefab. That rule makes sense, since a prefab can be spawned in any scene.

avatar image alienbaby · Dec 06, 2013 at 11:16 PM 0
Share

Cheers, altogether this helped me work it out.

I ended up with this in a script on the camera;

 var HUDScorePrefab: GameObject;
 
 
 @HideInInspector
 var HUDScoreCloneText$$anonymous$$esh: Text$$anonymous$$esh;
 
 function Start () {
     var HUDScoreClone:GameObject=Instantiate(HUDScorePrefab,Vector3(0,0,0),Quaternion.identity);
     HUDScoreClone.transform.parent=transform;
     HUDScoreClone.transform.position=Vector3(-1.719547,0.8588534,0.8372908);
     HUDScoreCloneText$$anonymous$$esh=HUDScoreClone.GetComponent(Text$$anonymous$$esh);
     HUDScoreCloneText$$anonymous$$esh.text="0";
     
 }

And this on the object that wants to update textmesh text;

 function Start () {
     //get a reference to the scoreboard
     var mainCamera:GameObject=GameObject.Find("Shooting$$anonymous$$ovingCamera");
      var scriptHUD$$anonymous$$anager:HUD$$anonymous$$anager=mainCamera.GetComponent(HUD$$anonymous$$anager);
      HUDScore=scriptHUD$$anonymous$$anager.HUDScoreCloneText$$anonymous$$esh;
 }

which then just uses HUDScore.text to set the text, and everything updates fine.

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Shooting at ground 1 Answer

How to make enemy AI with NavMesh 2 Answers

Climb ladder 2 Answers

C# Unity Script Examples & Question 2 Answers


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