Steve_Zhang Posted August 18, 2025 Share Posted August 18, 2025 (edited) Hi! [modmain.lua] AddPrefabPostInit("compfire", function(inst) inst:AddTag("custom_tag123") end) [widgets/mywidget.lua] local x, y, z = self.owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 50, {"custom_tag123"}) TheSim:FindEntities can not find custom tag "custom_tag123". Please tell me how to fix it. Edited August 18, 2025 by Steve_Zhang Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/ Share on other sites More sharing options...
Steve_Zhang Posted August 18, 2025 Author Share Posted August 18, 2025 (edited) Hi! [modmain.lua] AddPrefabPostInit("compfire", function(inst) inst:AddTag("custom_tag123") end) [widgets/mywidget.lua] local x, y, z = self.owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 50, {"custom_tag123"}) TheSim:FindEntities can not find custom tag "custom_tag123". Please tell me how to fix it. Edited August 18, 2025 by Steve_Zhang Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832139 Share on other sites More sharing options...
IronHunter Posted August 18, 2025 Share Posted August 18, 2025 Did you make a typo for campfire and called it compfire? Because I assume your trying to add it to the campfire prefab. Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832169 Share on other sites More sharing options...
Steve_Zhang Posted August 19, 2025 Author Share Posted August 19, 2025 (edited) 6 hours ago, IronHunter said: Did you make a typo for campfire and called it compfire? Because I assume your trying to add it to the campfire prefab. Apologies, I made a spelling mistake with the word 'campfire'. This is merely an example. The problem is still as per the title. Is it because the widget can't access the custom tags added on the mastersim? Edited August 19, 2025 by Steve_Zhang Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832208 Share on other sites More sharing options...
FerniFrenito Posted August 19, 2025 Share Posted August 19, 2025 Hi, your code works for me. I think your problem is one of these: You didn't put FindEntities() in a DoPeriodicTask. The function only searches for entities one time when you call it. Maybe you aren't close enough to the campfire. Remember that the object must exist and be nearby. Maybe a confussion. The campfire object in the game is this: and you might think it's this (it happened to me) I also call local x, y, z = self.owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 50, {"custom_tag123"}) from a widget, so I don't think that's the problem. If you could pass your complete code, maybe I could be more helpful. Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832216 Share on other sites More sharing options...
Steve_Zhang Posted August 19, 2025 Author Share Posted August 19, 2025 (edited) 15 minutes ago, FerniFrenito said: Hi, your code works for me. I think your problem is one of these: You didn't put FindEntities() in a DoPeriodicTask. The function only searches for entities one time when you call it. Maybe you aren't close enough to the campfire. Remember that the object must exist and be nearby. Maybe a confussion. The campfire object in the game is this: and you might think it's this (it happened to me) I also call local x, y, z = self.owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 50, {"custom_tag123"}) from a widget, so I don't think that's the problem. If you could pass your complete code, maybe I could be more helpful. Here is my widget code, please take a look at it. local MyUI = Class(Widget, function(self, owner) Widget._ctor(self, "MyUI") self.owner = owner -- basic settings self:SetScaleMode(SCALEMODE_PROPORTIONAL) self:SetHAnchor(ANCHOR_MIDDLE) self:SetVAnchor(ANCHOR_MIDDLE) self:SetClickable(false) self:StartUpdating() end) function MyUI:OnUpdate(dt) local x, y, z = self.owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 50, nil, nil, {"custom_tag123"}) for _, ent in ipairs(ents) do if ent:IsValid() then print("prefab:", ent.prefab) end end end return MyUI Edited August 19, 2025 by Steve_Zhang Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832217 Share on other sites More sharing options...
FerniFrenito Posted August 19, 2025 Share Posted August 19, 2025 (edited) I hope no one saw what I posted before; it was a big lie. A widget's OnUpdate method does run, but to start it, you must use yourwidgetInstance:StartUpdating() You can use it at the end of your code to start updating when the object is finished creating by calling self:StartUpdating(). local myWidget = Class(Widget function() ... self:StartUpdating() end) Edited August 19, 2025 by FerniFrenito Final response Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832219 Share on other sites More sharing options...
Steve_Zhang Posted August 19, 2025 Author Share Posted August 19, 2025 (edited) 10 minutes ago, FerniFrenito said: Hi, It seems that the OnUpdate of the widgets are not executed alone, in fact, looking at the source code of the game they do not even have an OnUpdate method of any kind, but there is a code in the game to execute the OnUpdate of the screens, therefore the solution I propose is that you put your widget in a Screen and in the OnUpdate function of the screen execute the OnUpdate method of your widget The widget "MyUI" has been added to ThePlayer.HUD . And I'm sure that the OnUpdate of the widget can be executed. But "TheSim:FindEntities" just can not find the custom tag. Edited August 19, 2025 by Steve_Zhang Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832223 Share on other sites More sharing options...
FerniFrenito Posted August 19, 2025 Share Posted August 19, 2025 I'm very sorry, I made a mistake by answering too quickly without looking into the code enough, but I've already edited my response, and that solution will work for your problem. 5 minutes ago, Steve_Zhang said: The widget "MyUI" has been added to ThePlayer.HUD . And I'm sure that the OnUpdate of the widget can be executed. But "TheSim:FindEntities" just can not find the custom tag. If you are sure that OnUpdate is being executed, then I don't know what the problem could be. I used the exact same code without changing anything, and in my case, it works even with the same tag. Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832224 Share on other sites More sharing options...
Steve_Zhang Posted August 19, 2025 Author Share Posted August 19, 2025 (edited) 6 hours ago, FerniFrenito said: I'm very sorry, I made a mistake by answering too quickly without looking into the code enough, but I've already edited my response, and that solution will work for your problem. If you are sure that OnUpdate is being executed, then I don't know what the problem could be. I used the exact same code without changing anything, and in my case, it works even with the same tag. This mod is for Don't Starve Together, not Don't Starve . -- [[modmain.lua]] local MyUI = require("widgets/myui") AddPrefabPostInit("campfire", function(inst) inst:AddTag("custom_tag123") end) AddPlayerPostInit(function(inst) inst:ListenForEvent("playeractivated", function() if not TheWorld.ismastersim then if not inst.HUD then return end if not inst.steve_myui then inst.steve_myui = inst.HUD:AddChild(MyUI(inst)) inst.steve_myui:MoveToBack() end end end) end) -- [[widgets/myui.lua]] local Widget = require("widgets/widget") local MyUI = Class(Widget, function(self, owner) Widget._ctor(self, "MyUI") self.owner = owner -- basic settings self:SetScaleMode(SCALEMODE_PROPORTIONAL) self:SetHAnchor(ANCHOR_MIDDLE) self:SetVAnchor(ANCHOR_MIDDLE) self:SetClickable(false) self:StartUpdating() end) function MyUI:OnUpdate(dt) print("MyUI:OnUpdate") local x, y, z = self.owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 50, nil, nil, { "custom_tag123", "lighter" }) for _, ent in ipairs(ents) do if ent:IsValid() then print("prefab:", ent.prefab) end end end return MyUI In Don't Starve Together's console, using c_spawn("torch") will print "MyUI:OnUpdate" and "prefab: torch", but c_spawn("campfire") only prints "MyUI:OnUpdate". Therefore, I conclude that TheSim:FindEntities cannot find entities with custom tags. I just don't know why...... PS: The 'lighter' tag is a non-custom tag used to test whether TheSim:FindEntities works. Edited August 19, 2025 by Steve_Zhang Link to comment https://forums.kleientertainment.com/forums/topic/167616-helpthesimfindentities-can-not-find-custom-tags/#findComment-1832239 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