Hello Guest

Author Topic: Null reference exception in tk2dtextmesh.commit()  (Read 5067 times)

xfa27

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Null reference exception in tk2dtextmesh.commit()
« on: September 14, 2013, 06:33:24 pm »
Hi unikron,

Currently using 2d toolkit for my game. I got this strange problem when updating a tk2dtextmesh using tk2dtextmesh.Commit(), after assigning text from a int variable using tk2dtextmesh.text = (int variable).toString();

Sometimes it works, but after a few tries it returns a null reference exception, and after that it won't work anymore.

I'm currently calling the assigning and commit code using a event-delegate method. the text is a tk2dtextmesh in a scene that is assigned to the update script via drag and drop from the scene.

Here's the code : (note some name are replaced with ~ for privacy)

NullReferenceException
  at UnityEngine.Component.GetComponent[MeshFilter] () [0x00000] in <filename unknown>:0
  at tk2dTextMesh.Init () [0x00277] in /Volumes/Temp/~/TK2DROOT/tk2d/Code/Fonts/tk2dTextMesh.cs:505
  at tk2dTextMesh.Commit () [0x0002f] in /Volumes/Temp/~Assets/TK2DROOT/tk2d/Code/Fonts/tk2dTextMesh.cs:546
  at (wrapper delegate-invoke) EventsController/~Handler:invoke_void__this__ ()
  at (wrapper delegate-invoke)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Null reference exception in tk2dtextmesh.commit()
« Reply #1 on: September 15, 2013, 09:26:45 am »
Hi. How is your scene set up?
Do you have nested prefabs? There is a bug in Unity that resets objects in nested prefabs which could potentially cause this. Also, where is the delegate being called from?

xfa27

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Null reference exception in tk2dtextmesh.commit()
« Reply #2 on: September 16, 2013, 05:25:39 am »
Hi,

I don't have any nested prefab. All i did is just put a button prefab inside a tk2dcamera anchor.

Can I ask for your email ? It might be easier to send you a sample scene. What's odd is that it works at the beginning, but after a few times it just stop working and only work if the app is reinstalled.

gary-unikronsoftware

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 74
    • View Profile
Re: Null reference exception in tk2dtextmesh.commit()
« Reply #3 on: September 16, 2013, 09:15:16 am »
You can send your package to support at unikronsoftware.com

xfa27

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Null reference exception in tk2dtextmesh.commit()
« Reply #4 on: October 03, 2013, 04:30:23 am »
Hi,

Back on this. I am unable to duplicate it on a simplified project. It was quite a complex scene with multiple camera anchor but without any prefab (it was a score screen). The error happened when I combined using prime31 social networking, and I want to update the screen after a successful social post. It then will only happen after several times..

I don't know if this is unity bug or 2d toolkit bug, but right now I redone the entire scene simplified totally, and it works fine now. Thanks for the quick support and reply.