Jump to content

How to do stuff during the creation of a prefab?


Recommended Posts

I was under the impression that "prefabs" had a "fn" member, which was used to construct instances of that prefab. But doing this:

local prefab = GLOBAL.require "prefabs/walls" -- stone wall

local old = {
   fn = prefab.fn
}

local function fn(...)
   print("***************************** creating a stone wall")   
   local inst = old.fn(...)
   inst:AddComponent("named")
   inst:SetName("Hound bait")
   return inst
end
prefab.fn = fn
print("***************************** ready to create stone walls.")

The "ready to create" message is displayed successfully, but when I create a stone wall, my local "fn" is never called. It isn't called when I construct the wall, or when I place it. I've tried augmenting "fn" for stone walls, spears, and map scrolls, but it always does nothing.

Link to comment
Share on other sites

18 hours ago, Cunning fox said:

inst:DoTaskInTime(0, fn)

That... wouldn't do stuff during the creation of a prefab. It'd have to be already created, if I already had inst to work with. I want to add stuff to instances created by a prefab, during their creation process.

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...