Jump to content

Recommended Posts

Hey,

i have a question regarding the unwrappable component. I am trying to access the items in itemdata. When i am ingame and try to access the list via commandline using

inst.components.unwrappable.itemdata

it works and itemdata is not nil or empty.

However, i want to check the Contents of bundles right after they are created, so i tried to solve this using AddPrefabPostInit:

local require = GLOBAL.require
require "prefabutil"

local function CheckItems(inst)
      if not GLOBAL.TheWorld.ismastersim then
            return inst
      end
      local itemdata = inst.components.unwrappable.itemdata
      if itemdata ~= nil then
            for k,v in ipairs(itemdata) do
                  -- Do stuff with item v
            end
      end
end

AddPrefabPostInit("bundle", CheckItems)

This does not work. itemdata is always nil.

My best guess is that i am trying to access the contents before the game loads them. How can i ensure that my code runs after the bundle is completely loaded?

Hmm, have you tried running a DoTaskInTime(time, function)?

something like

inst:DoTaskInTime(0, function(inst)
--your code
      local itemdata = inst.components.unwrappable.itemdata
      if itemdata ~= nil then
            for k,v in ipairs(itemdata) do
                  -- Do stuff with item v
            end
      end
end)

This makes it run your code on the frame immediately after the rest of the bundle code is run.

I believe by default AddPostInit stuff runs your code before the default code is run.

That is how we are able to hook into existing functions to inject code.

Cheers,

Iron_Hunter

Edited by IronHunter

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...