Page 1 of 1

FindName returning null

Posted: 12 May 2014, 22:46
by Shavik
I will post a paste bin of my C# and XAML in their entirety below. (Please disregard style and such as this was supposed to be a quick demo of C# <-> XAML.)

I'm running into an issue assigning a control via the FindName method.

I saw two examples from sfernandez on the unity forums from last year.
http://forum.unity3d.com/threads/192064 ... ASED/page8

I have a pretty simple Grid -> Two Stack panels of Textblocks defined via XAML that I created with Blend for VS 2013.

I am able to get FindName to return the stackpanels and if I iterate over the children of the stack panels I see that they have the correct number of children but each child's GetName method returns an empty string which I assume has something to do with the FindName not finding it. A colleague of mine tried this and was successful.
The only work around I've found is to select the controls via a hard set GetChildren.Get(i) which is obviously not a long term solution.

Is it possible that this is due to the fact I'm using the Unity Trial? Everything else so far seems to work so I'd find it strange this small method would not function due to my trial status. I have fully purchased NoesisGUI on the asset store during the Madness sale and I am aware that I will have to purchase Unity Pro after my trial to continue using NoesisGUI.

Thanks for any and all help!

Attached Code Below
XAML: http://pastebin.com/hY706fEs
C#: http://pastebin.com/KSd98LEp
* Note: The code includes some extra fluff and other things I tried to get it working so the "current state" has diverged from the example provided in the aforementioned link.

Additional question: Should I be using a UserControl for this? When is the ideal time to use a UserControl over the way I've done it here? Example cases?

Re: FindName returning null

Posted: 12 May 2014, 23:06
by Shavik
Well after spending around 5 hours yesterday troubleshooting it, I think I've just fixed this on my own.

I was reading another post and the suggestion for an entirely unrelated issue was to go to the NoesisGUI settings and rebuild it.

I did that and it is successfully finding the controls now.

Hopefully this can help anyone else that may be having the same or similar issue.

Re: FindName returning null

Posted: 12 May 2014, 23:22
by wckdspn
If you edit and save a file while in play mode of the editor, it will fail to compile it. So changes can be missed if you do that. You can always build manually, so it's more of a minor annoyance. It would be nice if it could track files that changed while it was unable to overwrite them to process when it could. Not quite sure how to go about that. Might need some support from Unity's side.

Re: FindName returning null

Posted: 13 May 2014, 09:22
by sfernandez
If you edit and save a file while in play mode of the editor, it will fail to compile it. So changes can be missed if you do that. You can always build manually, so it's more of a minor annoyance. It would be nice if it could track files that changed while it was unable to overwrite them to process when it could. Not quite sure how to go about that. Might need some support from Unity's side.
This is something we will try to improve for next version. If something changes during play, we have to detect it and automatically build it when editor stops.

Re: FindName returning null

Posted: 13 May 2014, 18:38
by Shavik
I do want to state that this was not an issue of being in Play mode while editing. This persisted through Unity/Blend restarts and even full system restarts. It required a manual build.

Re: FindName returning null

Posted: 14 May 2014, 02:06
by jsantos
We have observed that sometimes Unity fails to notify us when a file changes. This also happens when installing the unity package. If this happens the best solution is saving again the XAML.

Anyway, this is far from ideal. We are considering the option of checking for changes ourselves (not relying in the notification sent by unity) each time the play button is pressed.

Re: FindName returning null

Posted: 14 May 2014, 02:08
by wckdspn
We are considering the option of checking for changes ourselves (not relying in the notification sent by unity) each time the play button is pressed.
If you do, make certain it's optional. I could see delaying play for the check to be potentially irritating for someone not immediately working on UI.

Re: FindName returning null

Posted: 14 May 2014, 02:15
by jsantos
It would be an incremental build. They are very fast. But yes, we need to take care with this decision.