First Person Controller + HDRP + Multiplayer Addon = Invisible Weapons Remote Players

denisfrs

Member
Hi!
I'm using the First Person Controller with the HDRP integration and the PUN Multiplayer Addon.
Following the documentation, i setup all my items considering this part of the manual:
If using a dedicated first person asset, the InvisibleShadowCastorHDRP material should manually be set on all of the third person objects that should be invisible (such as the head, arms, and items).

Now all the remote players have invisible guns, like the image below:
OnPaste.20220818-070432.png

I searched the forums and found this (https://opsive.com/forum/index.php?threads/picked-weapon-not-visualized-in-other-clients.3339/).
The solution there works, but now "my" player can see the first person weapons floating around, like the image below

OnPaste.20220818-070143.png


So i have two questions:
- My assets combination should work? (FPC + HDRP + Multiplayer)
- If so, how i can fix that? Am i missing some script that change weapons visibility on multiplayer addon?
 
- My assets combination should work? (FPC + HDRP + Multiplayer)
I haven't used HDRP with the PUN add-on so I'm not sure, but the PUN add-on doesn't change any rendering so I don't see why it wouldn't work. You should check the materials on the remote player to determine if those materials are correct. I would also ensure that you can get it working with the standard render pipeline first just so you have the workflow down.
 
After getting more into this, i think i know what is happening, one thing that i forgot to mention, is that these items are runtime pickups.

The RemotePlayerPerspectiveMonitor.cs is supposed to change the third person items material to a invisible shadow caster material, and indeed does that, but only once using the "OnAttachLookSource" event.
As my items are runtime pickups and the player still not picked any item, there's no material to change and the script destroy itself after that.

I guess this part of the documentation is missing a note, that if you're using remote players you should skip this step:
If using a dedicated first person asset, the InvisibleShadowCastorHDRP material should manually be set on all of the third person objects that should be invisible (such as the head, arms, and items).

But i still have questions, this is the default behavior or is a bug?
If is a bug, how can i fix it or work around?
 
I'm not sure why this would be different for HDRP compared to the standard render pipeline since it's just a material change. I will take a closer look at this for the next PUN update, but you could subscribe to the OnAddItem event and switch out the material when that item is picked up.
 
After setting up for multiplayer using the managers, if first person only, there is some steps needed to take after one is changing the materials back to correct materials, also adding the correct materials to the First Person Visible Materials array of the Third Person Object (just by memory sorry if naming isn't correct), and off hand I cannot remember if that was all, but I did give @Justin some code a short while back that should be in the next update that will resolve this.
 
Thank you @Justin and @FastSkillTeam for helping me with this.
Following the Justin advice, i made the script below based on the RemotePlayerPerspectiveMonitor.cs to swap the materials. I really don't know if this is the best solution, maybe FastSkillTeam had a better approach / code for this.

I'll be waiting for the upcoming updates, meanwhile here's my script to fix this:


C#:
using Opsive.Shared.Events;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Identifiers;
using Opsive.UltimateCharacterController.Networking;
using Opsive.UltimateCharacterController.Camera;
using Opsive.UltimateCharacterController.Items;
using UnityEngine;


public class TempMaterialChanger : MonoBehaviour
{
    public CameraController cameraController;
    [SerializeField] protected Material m_InvisibleMaterial;

    public Material InvisibleMaterial { get { return m_InvisibleMaterial; } set { m_InvisibleMaterial = value; } }

    private GameObject m_GameObject;
    private INetworkInfo m_NetworkInfo;

    bool firstPersonPerspective = false;

    private void Awake() {
        m_GameObject = gameObject;
        m_NetworkInfo = m_GameObject.GetComponent<INetworkInfo>();
        if (m_NetworkInfo == null) {
            Debug.LogError("Error: The character must have a NetworkInfo object.");
            return;
        }

        EventHandler.RegisterEvent<ILookSource>(m_GameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
        EventHandler.RegisterEvent<Item>(m_GameObject, "OnInventoryAddItem", Swap);
    }
    private void OnDestroy() {
        if (m_GameObject != null) {
            EventHandler.UnregisterEvent<Item>(m_GameObject, "OnInventoryAddItem", Swap);
            EventHandler.UnregisterEvent<ILookSource>(m_GameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
        }
    }

    private void OnAttachLookSource(ILookSource lookSource) {
        if (lookSource != null && m_NetworkInfo.IsLocalPlayer()) {
            cameraController = lookSource as CameraController;
            if (cameraController != null) {
                firstPersonPerspective = cameraController.ActiveViewType.FirstPersonPerspective;
            }
        }
    }
    void Swap(Item theItem)
    {
        if (firstPersonPerspective) {
            var thirdPersonObjects = gameObject.GetComponentsInChildren<ThirdPersonObject>(true);
            for (int i = 0; i < thirdPersonObjects.Length; ++i) {
                var renderers = thirdPersonObjects[i].GetComponentsInChildren<Renderer>(true);
                for (int j = 0; j < renderers.Length; ++j) {
                    var materials = renderers[j].materials;
                    for (int k = 0; k < materials.Length; ++k) {
                        materials[k] = m_InvisibleMaterial;
                    }
                    renderers[j].materials = materials;
                }
            }
        }
    }
}
 
The code I am referring to is actually used in the character setup process for first person only controllers and is an edit to UCC code for installs also, all it does is setup the components correctly if user only has FirstPersonController, from there it works perfectly. That being said I wrote the code to save this kind of question being asked in the future, but all it does is ensure there is no user error, so this can be achieved by ensuring your components are indeed setup correctly (NOTE: there is a bug current that does make first person items invisible if starting in third person and using runtime pickups, due for fix in next update also, I have made a thread on this). Looking at your code it would actually fix the NOTE I think too for now. I do something similar for mat swaps in my asset.
 
Top