How to do stuff during the creation of a prefab?

Recommended Posts

kertinker    109

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:SetName("Hound bait")
   return inst
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.

Share this post

Link to post
Share on other sites
kertinker    109
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.

Share this post

Link to post
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