Gun only appears on camera when viewed in scene view

I appear to have a strange problem:
I have created a pistol with hands, among other gun models, and when the player spawns in the pistol and hands are not there. If you then swap to the scene view and look at the player the pistol appears on both the scene view and on the camera. After this is done the pistol acts as expected; the animations play and the script works.

What is stranger is that this is not a problem that I face with the other models I have made, such as the sniper which is in the same position and is viewed by the same camera with the same parenting as the pistol.

While I have been looking through the forums I cannot find anyone else with my problem and can see no way to fix this. It would be great if someone could give me a step in the right direction towards sorting this problem. Any help is much appreciated.

Thanks

Is it set to a different layer and is your camera set to ignore that layer? Perhaps it’s that simple.

This sounds like a Bounds issue to me. Perhaps try calling yourProblematicMesh.RecalculateBounds() and see if that fixes the problem?

Thank you, drewradley and StarManta for getting back to me so quickly. I checked the layer of the pistol and arms and each part was a member of the gun layer, as was the sniper. I then tried to use the RecalculateBounds() void but this cause the genericPistols script to log many errors in the console;

NullReferenceException: Object reference not set to an instance of an object
genericPistols.updateGun () (at Assets/GunModels/Pistols/genericPistols.cs:92)
UnityEngine.GameObject:SendMessage(String)
movement_mouseLook:handleGuns() (at Assets/Player Assets/movement_mouseLook.cs:625)
movement_mouseLook:NormalProcedures() (at Assets/Player Assets/movement_mouseLook.cs:285)
movement_mouseLook:Update() (at Assets/Player Assets/movement_mouseLook.cs:171)

I had implemented the code in the Awake() void of the genericPistols script in the form shown;

GetComponent().mesh.RecalculateBounds();

As I said, this causes the problem as shown above in other lines of code.

However, I had a bounds issue before in which the pistol, having been seen on the scene view would still appear or disappear and I got past this by turning on “Update when off screen” on the renderer. Surely this would solve any bounds issues?

I am very unsure of how to get past this problem and I need this to work for the game to be functioning.

Again, thanks for getting back so quickly.

To those of you that have the same problem, although I doubt there are many, I managed to solve it by making the weapon animate even when it was not being viewed by setting the culling type of the animator to “Always Animate”.

The problem was that in the weapons starting position it was not viewed by the camera. Viewing the pistol from the scene view then caused the start animation to play so that the pistol was then in the view of the main camera and acting normally. The sniper did not face this problem because it was longer than the pistol and could be viewed by the main camera in its start position.

Again thank you to those that provided help with this problem and I hope that this solution will help others in the future.