Acquire input warning and proxies (SOLVED)

I’ve noticed the new warning for acquire input messages being called multiple times on an object, which is great info!

However, I’ve been trying to fix the warnings, but I’m not sure if I’m doing something wrong or if it’s a bug in the warning.

My structure looks like this:

function init(self)
	msg.post("#menu", "async_load")
end

function on_message(self, message_id, message, sender)
	if message_id == hash("load_level") then
		print("loading level...")
        if self.loading_state then
    		return
    	end
    	
    	self.loading_state = hash("loading_screen")
    	self.loaded_level = message.level
    	msg.post("#loading", "async_load")
    	    	
    elseif message_id == hash("proxy_loaded") then
    	print(sender)
    	msg.post(sender, "enable")
    	msg.post(sender, "acquire_input_focus")

    end
end

So the warning comes from the proxy_loaded case, where it enables the proxy and calls acquire_input_focus which is needed as far as I understood to get the proxy object to start receiving input. The output log looks like this:

DEBUG:SCRIPT: url: [main:/root#menu]
DEBUG:SCRIPT: loading level...
DEBUG:SCRIPT: url: [main:/root#loading]
WARNING:GAMEOBJECT: Input focus already acquired for instance with id: '/root'.

Any pointers to how I can restructure the code to get rid of the warning or is it a bug?

No, it’s not a bug. Since you load two proxies and acquires input in both cases you get the warning.

The easiest solution is to simply do:

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#menu", "async_load")
end

function on_message(self, message_id, message, sender)
	if message_id == hash("load_level") then
		print("loading level...")
        if self.loading_state then
    		return
    	end
    	
    	self.loading_state = hash("loading_screen")
    	self.loaded_level = message.level
    	msg.post("#loading", "async_load")
    	    	
    elseif message_id == hash("proxy_loaded") then
    	print(sender)
    	msg.post(sender, "enable")
    end
    ...
3 Likes

Ah, I thought each proxy needed the acquire_input_focus message. Thanks!

3 Likes

It is actually the game objects that acquire focus. The object then broadcasts all input to all its components, including collection proxies. So in your case you were in effect doing:

msg.post("/root#menu", "acquire_input_focus") -- "root" added to input stack
msg.post("/root#loading", "acquire_input_focus") -- "root" added to input stack again
1 Like