GetLayoutForDevice error (Unity)

18 views
Skip to first unread message

Mario von Rickenbach

unread,
Aug 18, 2012, 7:54:24 PM8/18/12
to brassmo...@googlegroups.com
Is this the right place to ask for help when developing with the brassmonkey unity SDK?

I'm trying to activate a texture on the device layout when it connects, but following error occurs when trying to get the device layout:

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,BMControlLayout].get_Item (System.String key)
BMControlScheme.GetLayoutForDevice (BMDevice device)
InputManager.OnDeviceStateChange (INetConnection connection, BMDevice device, ConnectionState fromState, ConnectionState toState) (at Assets/Scripts/InputManager.cs:25)
BMConnection.OnDeviceStateChange (INetConnection connection, BMDevice device, ConnectionState fromState, ConnectionState toState)
BrassMonkey.IO.UDPNetConnection.HandleInternalMessage (BMInternalMessenger sender, System.String messageId, System.Object[] parameters)
BrassMonkey.Util.BMMessengerService.ProcessMessages ()
UnityMessengerService+<Tick>c__IteratorD.MoveNext ()

I'm using v1.0.6 of brassmonkey with unity 3.5.5f2. The device is connected and shows the layout, input works.

Here's the code where the error occurs:

Any ideas what's wrong?

Francois Laberge

unread,
Aug 18, 2012, 9:54:58 PM8/18/12
to brassmo...@googlegroups.com, brassmo...@googlegroups.com
Hey Mario,

Yep, this is the ideal place for asking about trouble shooting questions. We're looking into your issue and will get you an answer as fast as we can.

Love your work,
Francois

Sent from my iPhone
--
 
 
 

Zach Kamsler

unread,
Aug 18, 2012, 11:09:01 PM8/18/12
to brassmo...@googlegroups.com
I see the problem.

Since the library chooses the control scheme based on the device
resolution, there is no device-specific control scheme until it gets
the control scheme request from the device. The appropriate thing to
do in this situation is to listen to the
BMControlScheme.Instance.OnDeviceLayoutCreated and make the desired
changes in the event handler. There is no need to call
UpdateControlScheme, because this is before the initial control scheme
is first sent. You can see an example of this in the dynamic control
scheme sample code.

It might look something like:
https://gist.github.com/9956c9b38975fa0b5cbc

The library probably ought to be changed to do something a bit more
helpful than throwing an oblique exception when the control scheme is
accessed too early.

-Zach Kamsler
> --
>
>
>

Mario von Rickenbach

unread,
Aug 19, 2012, 5:00:48 AM8/19/12
to brassmo...@googlegroups.com
Ok great, that works, thanks!

I took the code from page 11 of the getting started pdf, where it is not mentioned that this action it is not available on connect, maybe a hint would be good there. 

Is there a html api reference somewhere? would be nice, because scrolling throungh a pdf is a bit impractical.

Francois Laberge

unread,
Aug 19, 2012, 9:29:55 AM8/19/12
to brassmo...@googlegroups.com, brassmo...@googlegroups.com
I've been meaning to make an HTML version of the docs. Let me see what I can do.

Sent from my iPhone
--
 
 
 

Francois Laberge

unread,
Aug 20, 2012, 11:33:42 AM8/20/12
to mariovonr...@gmail.com, brassmo...@googlegroups.com
hey Mario,

I created an HTML version of our GettingStarted.pdf, it can be found here. I'm updating the website to include it as we speak:
http://playbrassmonkey.com/developers/unity/docs/getting-started.html

Francois
--
Francois Laberge
CTO
Brass Monkey Inc.
San Francisco | Boston

Mario von Rickenbach

unread,
Aug 23, 2012, 9:33:52 AM8/23/12
to brassmo...@googlegroups.com, mariovonr...@gmail.com
thanks for the HTML docs!

I noticed another problem with my layouts: When I change the layout before sending, everything works fine, but when I try to send it again later, first it works, but after doing it a few times, updating the layout fails. After the OnDeviceLayoutCreated event, the layout should stay available, right? 

Currently I'm doing the layout switch in OnLevelWasLoaded, where it should load the right layout for the game or menu. Because it is possible that the scene changes before the initial layout is ready, I added a check if the layout is already there. For this, I just saved the layout on first creation. Everything works for the first time from menu to game and back, but the second time I change to a game-scene the UpdateControlScheme fails with this error message:

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,BMControlLayout].get_Item (System.String key)
BMControlScheme.GetLayoutForDevice (BMDevice device)
BMControlScheme.GetUpdateXmlForDevice (BMDevice device)
BMConnection.UpdateControlScheme (BMDevice device)
InputManager.OnLevelWasLoaded (Int32 lvlId) (at Assets/Scripts/InputManager.cs:90)

Here's the relevant code:

Francois Laberge

unread,
Aug 23, 2012, 9:58:18 AM8/23/12
to brassmo...@googlegroups.com, mariovonr...@gmail.com
Hey Mario,

We'll look into that this morning and get you some answers. Looking forward to how you are using our dynamic controller features!

Francois

Zach Kamsler

unread,
Aug 23, 2012, 1:30:04 PM8/23/12
to brassmo...@googlegroups.com, mariovonr...@gmail.com, fran...@playbrassmonkey.com
I do not have much experience with using Brass Monkey in multi-scene projects, but I think I might have an idea of what might be happening. ThBMControlScheme instance gets clobbered if a new instance of the component's Awake method is called. BMConnection already had code to prevent it from being clobbered, and it didn't matter much if BMControlScheme had been clobbered without dynamic control schemes.

I changed BMControlScheme to not overwrite the existing instance if there was one, and added a

HasLayoutForDevice method in case you did not feel like caching the layouts.

I have attached a unity package containing just the updated dll. Please let me know if it fixes the issue.

-Zach Kamsler

BrassMonkey-MultiSceneControlsFix.unitypackage

Mario von Rickenbach

unread,
Aug 23, 2012, 1:52:55 PM8/23/12
to brassmo...@googlegroups.com, mariovonr...@gmail.com, fran...@playbrassmonkey.com
just tried it, something doesn't work with this dll, can't connect:

(on startup)

08/23/2012 19:46:43: BrassMonkeyAuthenticationModule : Error in getting data: couldn't connect to host
UnityEngine.Debug:LogError(Object)
BrassMonkey.Util.Logging.UnityLogger:Print(String, String, Object[])
BrassMonkey.Util.Logging.ConsoleLogger:Error(String, Object[])
BrassMonkey.Util.Logging.LoggerFactory:Error(String)
BrassMonkey.Util.Logging.CategoryLogger:Error(String)
<CheckWebService>c__Iterator0:MoveNext()

Zach Kamsler

unread,
Aug 23, 2012, 2:19:54 PM8/23/12
to brassmo...@googlegroups.com
There were some issues with the Brass Monkey servers this morning, and the error that you see is consistent with that. The servers should all be back up as of noon EST. If this error still continues, you could try restarting Unity in case you have something cached. I will double check that the servers are operational.

-Zach

--
 
 
 

Mario von Rickenbach

unread,
Aug 23, 2012, 3:01:34 PM8/23/12
to brassmo...@googlegroups.com
ok, that obviously was the problem, now it works. thanks for the quick fix!
check it out here: http://mariov.ch/rakete/brassmonkey/
(ok, going back to the menu is right now only possible by pressing esc and then q on the keyboard, but now that it works I could add buttons on the device to do that.. let's see)
Reply all
Reply to author
Forward
0 new messages