luadefold

How do I get input from a collection proxy in Defold


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

Solution

  • 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.