Unity develops tips three UGUI-Lua Component Recycling

ugui tolua

local test = {}

test.b = gameobject
test.c = gameobject:GetComponent(typeof(UnityEngine.UI.Button ))

First call UnityEngine.GameObject.Destroy(test.b)
If the test table is also recycled by ToLuaUnRef, it is found that
test.c references the Button object in c#. Released from ObjectTranslator.objectsBackMap

The object in ObjectTranslator is not released, it should be you still refer to this object in Lua. The normal practice is to ensure that the references in Lua are released in time, but there will be a lot of code with xxx=nil. If the project does not pay attention to these at the beginning, it will be very annoying to change it later. Our approach is to traverse in BasePanel

function BasePanel:cleanVar() for k,v in pairs(self) do if (type(v) == "userdata" or type(v) == "table") and k ~= "gameObject" then self[k] = nil end endend

To close the UI interface is to call cleanVar() in OnDestroy()

function BasePanel:cleanVar() for k,v in pairs(self) do if (type(v) == "userdata" or type(v) == "table") and k ~= "gameObject" then self[k] = nil end endend

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3246 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.