Loading my levels via collection proxy completely messes up acquire_input_focus of components (SOLVED)

Hi all,

I first designed my levels individually and each level had 3 gameobjects that would acquire_input_focus:

  • game_manager: this would allow me to tap on sprites in game.
  • game-gui: allowing me to click on the pause button and UI buttons.
  • status UI: this would be a column of buttons that would enable and appear next to a gameobject that would allow me to click on them.

in the init(self) of all these components I have written: msg.post(".", "acquire_input_focus").

Everything was working perfectly and there were no problems , none of the elements overlap and even if they do, I would consume the input by return true.

Now that I have a few levels designed, I wanted to add them to my main menu collection so that they could be loaded up when needed.

And immediately I had problems and the input would not work when loading the levels.

I solved this by adding the following line to my level_loader.script:

elseif message_id == hash("proxy_loaded") then
		-- auto sent by collection proxy after it has been loaded to memory, so we just enable it
		msg.post(sender, "enable")
		
		-- Pass input focus to the newly loaded level
		msg.post(sender, "acquire_input_focus")

Adding the line msg.post(sender, "acquire_input_focus") made the input to work again and I could have the functionality of my game_manager input.

But this works only if I keep the msg.post(".", "acquire_input_focus") in my game_manager.script, if I comment it out it wont work.

whats more is that now the game UI and the status UI dont work, although they have msg.post(".", "acquire_input_focus") in their init(self) functions.

so to fix this I added the following to my game_manager:

msg.post(".", "acquire_input_focus")
	msg.post("game_gui#game_gui", "acquire_input_focus")

and the UI started working again.

And now I have to do this every time any gameobject releases input focus, I have to call a function that will request the input focus for all gameobjects in scene.

for example when the game is pause, I dont want the player to interact with the towers so I do msg.post(".", "release_input_focus") when the game is paused and then do msg.post(".", "acquire_input_focus") when the game resumes.

But by doing that the UI no longer works and the status panel also stops working unless I sequentially request input focus for all component as explained above.

is this the correct way to do this? I feel this may not be the right way and Im doing something wrong here.

Take a look at these docs:
https://defold.com/manuals/collection-proxy/#caveats-and-common-issues
And
https://defold.com/manuals/input/#input-focus-and-collection-proxy-components

I think that’s answer for your problem.

3 Likes

thank you, that helped. and my another mistake was that I was consuming input in game_manager and that is why the touch was not reaching UI. silly mistake on my part