Sign in to follow this  
_Q_

List of prefabs

Recommended Posts

_Q_    644

Is there a way I could print a list of all prefabs with invenotryitem component to the log file?

Or I just need to go to the prefab folder and do it all manually.

 

Share this post


Link to post
Share on other sites
DarkXero    2893
local assertive = {	world = true, cave = true, forest = true, shard_network = true, world_network = true, forest_network = true, cave_network = true,	maxwellthrone = true,} -- These can only exist once, and the throne needs a profileprint("Prefabs with inventoryitem")for k, v in pairs(Prefabs) do	if not assertive[k] then		local inst = Prefabs[k] and Prefabs[k].fn and SpawnPrefab(k) -- backpack skins have no fn		if inst and inst.components and inst.components.inventoryitem then			print(inst.prefab)			inst:Remove()		end	endend

works once I filtered prefabs that didn't like existing more than once, or never.

 

Share this post


Link to post
Share on other sites
Maris    234
local all_inventoryitem_objects = {}AddComponentPostInit("inventoryitem",function(self)	table.insert(all_inventoryitem_objects, self.inst)end)GLOBAL.rawset(GLOBAL,"print_all",function()	for i,v in ipairs(all_inventoryitem_objects) do		if v:IsValid() then			print(tostring(v))		end	endend)

Share this post


Link to post
Share on other sites
Mobbstar    14123
local all_inventoryitem_objects = {}AddComponentPostInit("inventoryitem",function(self)	table.insert(all_inventoryitem_objects, self.inst)end)GLOBAL.rawset(GLOBAL,"print_all",function()	for i,v in ipairs(all_inventoryitem_objects) do		if v:IsValid() then			print(tostring(v))		end	endend)

 

 

Though I recommend to use the prefab names as keys and true as a dummy value. Not only does this cut the annoying GUID away, but also it prevents duplicates (which will happen a lot otherwise)

Share this post


Link to post
Share on other sites
Maris    234
Though I recommend to use the prefab names as keys and true as a dummy value. Not only does this cut the annoying GUID away, but also it prevents duplicates (which will happen a lot otherwise)

it depends on what you need - all objects or just prefab names.

(I'm not sure why someone need prefab names in existing active world, because AddPrefabPostInit already does not work at that momet).

 

And yes, this is dirty code, but this is only an example.

Edited by Maris

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
Sign in to follow this