Nelzanger Posted September 6, 2021 Share Posted September 6, 2021 (edited) Hello, I'm trying to make a gauge mechanic for my custom character when equipping a hat. After checking how some components works (like health, moisture or hunger), I've decided to make a simple custom component, placed in the "components" folder of my mod, to check if it has been correctly added. Its content is shown below : --hateffect.lua local Hateffect = Class(function(self, inst) self.inst = inst self.maxEffect = 100 self.minEffect = 0 self.current = 50 end) return Hateffect However, when I use inst:AddComponent("hateffect") in the function to make my hat prefab, trying to access it afterwards tells me that inst.hateffect is null. I thought it might be a initialization issue, so I also tried add the component when equipping the hat, with the code below, while still having the component added in the prefab function : -- MyHat:OnEquip(inst, owner) inst:AddComponent("hateffect") if (inst.hateffect == nil) then print("ERROR : THE HAT COMPONENT IS STILL NULL") else print("THE HAT COMPONENT HAS BEEN ADDED !") end But I got the following logs, that tell me my custom component already exists, but when tested with the code above, says it's still null : [00:00:37]: Registering master server in EU lobby [00:00:45]: Resuming user: session/0D653EA1B3E0311F/A7JL7RU4BBIS/0000000260 [00:00:45]: ERROR : THE HAT COMPONENT IS NULL [00:00:45]: Spawning player at: [Load] (91.37, 0.00, 99.96) [00:00:45]: Sim unpaused [00:00:47]: Registering master server in EU lobby [00:01:03]: component hateffect already exists on entity 118107 - damage_hat(LIMBO)! [00:01:03]: ERROR : THE HAT COMPONENT IS STILL NULL Important note : Disabling the addComponent in the prefab function, and letting the code in the OnEquip didn't work either, the component stays null. I've checked other mods' scripts to see how custom components are added, but so far, it seems that everything is managed in modutils.lua when creating a new custom component, and that calling your custom component in inst:AddComponent is enough. So what did I miss here ? Why my component is still null when I'm trying to use it, but the log tells me that it already exists ? Edited September 6, 2021 by Nelzanger Added precisions 1 Link to comment https://forums.kleientertainment.com/forums/topic/133342-solvedcustom-component-is-null/ Share on other sites More sharing options...
Nelzanger Posted September 6, 2021 Author Share Posted September 6, 2021 Nevermind When adding a component, a correct call is to access the components table like this. inst.components.hateffect I must be tired. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/133342-solvedcustom-component-is-null/#findComment-1491679 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now