The issue is after unloading the object the object unloads and never loads back.
I tried replacing registeredcframes table with attributes, tried lower unload cframe, debugged everything, overall did everything to resolve this issue but couldnt resolve it please help.
Here’s the code of my module(it’s gonna be opensource):
-- Created by 1Xayd1
local RenderCache = {}
RenderCache.__index = RenderCache
export type RenderCacheType = {
MovingParts: {BasePart},
MovingCFrames: {CFrame},
RegisteredCFrames: {[BasePart]: CFrame},
unloadCFrame: CFrame,
Updating: boolean,
new: () -> RenderCacheType,
Register: (self: RenderCacheType, array: {BasePart}) -> (),
Update: (self: RenderCacheType) -> (),
Load: (self: RenderCacheType, Part: BasePart) -> (),
Unload: (self: RenderCacheType, Part: BasePart) -> ()
}
function RenderCache.new(): RenderCacheType
local self = setmetatable({}, RenderCache)
self.MovingParts = {}
self.MovingCFrames = {}
self.RegisteredCFrames = {}
self.unloadCFrame = CFrame.new(2^24, 2^24, 2^24)
self.Updating = false
return self
end
function RenderCache:Register(array: {BasePart})
for _, part in ipairs(array) do
self.RegisteredCFrames[part] = part.CFrame
end
end
function RenderCache:Update()
if self.Updating then warn("Tried to update while updating, skipping.") return end
self.Updating = true
workspace:BulkMoveTo(self.MovingParts, self.MovingCFrames, Enum.BulkMoveMode.FireCFrameChanged)
table.clear(self.MovingParts)
table.clear(self.MovingCFrames)
self.Updating = false
end
function RenderCache:Load(Part: BasePart)
if not self.RegisteredCFrames[Part] then
warn("Part not registered in cache!")
return
elseif self.Updating then
warn("Cannot load | unload objects while updating.")
return
end
table.insert(self.MovingParts, Part)
table.insert(self.MovingCFrames, self.RegisteredCFrames[Part])
end
function RenderCache:Unload(Part: BasePart)
if not self.RegisteredCFrames[Part] then
warn("Part not registered in cache!")
return
elseif self.Updating then
warn("Cannot load | unload objects while updating.")
return
end
table.insert(self.MovingParts, Part)
table.insert(self.MovingCFrames, self.unloadCFrame)
end
return RenderCache
function RenderCache:Register(array: {BasePart})
for _, part in ipairs(array) do
self.RegisteredCFrames[part] = part.CFrame
end
print(#self.RegisteredCFrames) -- will print 0
end
Can you clarify what you mean by this? Are you referring to the Unload and Load functions and if so, what is the expected behavior when you load an object back?
print(#self.RegisteredCFrames) -- will print 0
As for this, you’re using RegisteredCFrames as a dictionary and not an array. Since there are no indexed elements, #self.RegisteredCFrames will always be 0 even if there are elements in the table.
Do you run this code on the server or client? If it’s on the client, my only guess is that when you unload an object, you move it so far away that it gets streamed out and when you try and move it back, it no longer exists.
Other than that, I don’t really know why it wouldn’t be working. Are you seeing errors or logs or anything? My only other suggestion would be to print the various tables when you call Load, Unload, or Update and confirm the data is how you expect it to be.
Oh wait i didnt that might be it though! I hqte streaming so much btw its breaking things and just looks ugly thats why i am developing blazing fast cull module for this.
As i said i tried working with attributes, attribute stored original cframe and it was static i checked, but again, it unloaded the part and never loaded it back. But I will try
What happens is that when load and unload the same object before a update the table is not cleared, this makes so there’s 2 registers of the same part before the update.
Load → Adds the position and part to the table
Unload → Also adds the unload position and part to the table
edit: you should check in the unload function, to see if the part was added already to the table and if so edit the cframe to the void one