Reputation: 7576
I have loaded a collection proxy but I receive no input on the scripts inside the proxy even if I have input focus on the loader object. I also receive no input on the loader object.
This is the script that loads the proxy:
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("/game#level1", "load")
end
function on_message(self, message_id, message, sender)
if message_id == hash("proxy_loaded") then
msg.post(sender, "enable")
end
end
And this is a script on an object in the proxy:
function init(self)
msg.post(".", "acquire_input_focus")
end
Upvotes: 3
Views: 441
Reputation: 2689
As explained in the documentation: https://defold.com/manuals/input/ and @Mikael, the gameobject holding the proxy needs to acquire_input_focus
.
One simple way I achieve this is by sending a message to the sender after proxy_loaded
message is received:
elseif message_id == hash("proxy_loaded") then
-- collection has been loaded to memory, so we just enable it
msg.post(sender, "enable")
print(sender)
-- Pass input focus to the newly loaded level
msg.post(sender, "acquire_input_focus")
This will automatically pass the input focus to the level that was just loaded.
Also leave the acquire_input_focus
within the gameobject of the loaded level as well. In my experience both are needed for input focus to properly hand over. i.e. within the gameobject of the loaded scene that needs input have the following:
function init(self)
msg.post(".", "acquire_input_focus")
end
Upvotes: 0
Reputation: 131
This is a pretty common pitfall. Input and proxies work like this: each proxy loaded collection has their own input stack. Input is routed from the main collection input stack via the proxy component to the objects in the collection. This means that it’s not enough for the game object in the loaded collection to acquire input focus, the game object that holds the proxy component need to acquire input focus as well. See the Input documentation for details.
Upvotes: 5