Changing prefabs on weapons.

Hi FPS.Sample Game Community o/

I got this issue I need help with. I hope someone in this community have a solution they would like to share.

I'm trying to make more weapons based on the 2 original weapons. Adjusting the weapons attributes and make them act like a different weapon isn't a problem. When I try to change the prefab I run into issues. I managed to make it work on the client(preview mode), but I get a NullReferenceException when I use “Start”.

The Item_TerraformerWeapon takes the the following inputs:

  • Script: ItemTypeDefinition

  • Prefab Server(): None (Game Object)

  • Prefab Client: Item_TerraFormerWeapon_Client (Base: Terraformer_Weapon_A_3P)

  • Prefab 1P: Item_TerraFormerWeapon_1P

  • Ability Prim Fire: Ability_AutoRifle(Ability_AutoRifle)

  • Ability Sec Fire: Ability_ProjectileLauncher(Ability_ProjectileLauncher)

So my question is the following:

  • What is the best way to copy this weapon and use another prefab so it work on the server and on the client?

What I have tried already:

  • Copying the “Item_TerraFormerWeapon_1P” by dragging it over in “Hierarchy”, making a new folder and dragging it into there. And choosing the “Create a new original prefab”.

  • Right clicking on the “Item_TerraFormerWeapon_1P” → Create → Prefab Variant. Renaming it and using it as the new weapons “Prefab 1P”. (This option makes it work in preview mode).

  • Made a new prefab from start with a new game object.

Hello Toldam,

You will want to make a bunch of new prefabs(NOT COPY), and register them as well. Do a search for all the terraformerweapon (attached are some pointed examples from the robotweapon) items in the game and you will find things you should RE-CREATE to build an alternate weapon. Name the new prefabs after the gun you are crafting (below I named my prefabs m240 in place of 'robot' on all the prefabs.)

Each new prefab, needs to then be REGISTERED in multiple ways, to correct update and be found by client and server versions (to include, you will need to rebuild the game/scripts when you register new items I believe.) I talked about registeries a little here :

In-game switching of guns I believe you would need to write yourself, although they mention in the code that they are going to add a change gun when more than one gun is put in per character.

For me/now/testing, just to see it work, I created 2 new characters(and figured out how to do that!), and gave them my new gun... The video below is after I did a next-char to my new character, who had the new m240 gun prefabs all registered and such, as that character's only inventory item/gun.

Sadly I don't have time today to re-do any guns, and I deleted that version of the sample that had the m240s in it after I got it working :)


Hi Micah,

Thanks for the answer and your time. it helped a lot. The issue was that I hadn’t registered the entry in the shared folder. I found a way to use the prefabs even though it’s a copy of another. I’ll share the solution in this thread monday and try to explain the approach step by step.

Have a great weekend! \o/


Whoops! I took some pictures of that area to post and forgot to, so I am glad you found them :) Here are the screenshots anyway



1 Like

Here is a guide to how I did it. Forgive me if it's not that great. I'm new to Unity and making guides :smile:


VERY COOL TOLDAM! Great to see the start of some tutorials out there :smile:!!

One note that you may run into, is that manually adding +1 to the registeries I think is the wrong way to do it. I think you need to recreate the sub-items and hit “register” instead of doing that by hand. When I have done it by hand, by increasing the shared registeries themselves, its caused errors when actually testing the game outside of the editor. (aka running a server and client)

Keep up the great work man!!!

I agree, it's not a great way to do it. But I couldn't figure out any other way to do it. I haven't had any issues when running the game tho. I'll see if I can use your method.