Jump to content

Which is the best way for overriding prefab component function ?


Recommended Posts

This way ?

AddPrefabPostInit("existingprefab", function(inst)
	if inst.components.existingcomponent then
		local Old_ExistingFunction = inst.components.existingcomponent.ExistingFunction
		function inst.components.existingcomponent:ExistingFunction(...)
			print("Overridden !")
			return Old_ExistingFunction(self, ...)
		end
	end
end)

or this one ?

local ExistingComponent = GLOBAL.require("components/existingcomponent")

local Old_ExistingFunction = ExistingComponent.ExistingFunction
function ExistingComponent:ExistingFunction(...)
	if self.inst.prefab == "existingprefab" then
		print("Overridden !")
	end
	
	return Old_ExistingFunction(self, ...)
end

 

 

 

Edited by waw
typo
Link to comment
Share on other sites

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
 Share

×
  • Create New...