• RuntimesUnity
  • Help fix in my player's arm why does it detached in the body?

So I have a problem in the animation of my player. I want that when I carry a gun, my hand and the gun will follow the direction of my crosshair. But what happened is that when I try to carry the gun it detaches in my body.

This is the part where I didn't include the aim animation I just use the animation for holding the item:

Then this part is where I include an aim animation:

Related Discussions
...

This is the code for the player's animation:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using DG.Tweening;
using EatTheRich.Utilities;
using Photon.Deterministic;
using Quantum;
using Spine;
using Spine.Unity;
using UnityEngine;
using UnityEngine.UIElements;
using Sequence = DG.Tweening.Sequence;

namespace EatTheRich
{
public unsafe class UnityPlayerAgentAnimation : MonoBehaviour
{
public int headAccessoryIndex;
public int eyeIndex;
public int outfitIndex;
public int legOutfitIndex;
public int skinToneIndex;
public int accessoryIndex;
private List<string> headSkins;
private List<string> eyeSkins;
private List<string> outfitSkins;
private List<string> legOutfitSkins;
private List<string> skinTones;
private List<string> accessorySkins;
[SerializeField] private SkeletonAnimation _sklamPlayer;
private PlayerController _sklamPlayerController;

    #region Private Properties
    private EntityRef _entityRef = default;
    private QuantumGame _game = null;
    private bool _isInitialized = false;
    private Sequence _invulnerableTween;
    private bool _isEnabled;
    private bool _blnIsMoving;
    private bool _blnIsHoldingItem; // Track if the player is holding an item
    private bool _blnIsKnockedOut;
    private bool _blnIsDepositing; // Track if the player is in the deposit animation
    private bool _blnIsDashing;
    private bool _blnIsHurting;
    private bool _blnIsAttacking;
    private bool _blnIsHoldingWeapon;
    private float _fltIdleDelay = 0.2f; //When transitioning from moving to idle, add this delay so that when player immediately moves again he will no longer reset the running animation
    private float _fltCurrentIdleDelayValue = 0f;
    private Bone bone;
    public string boneName;
    #endregion

    #region Monobehaviours
    public void OnEnable()
    {
        _isEnabled = true;
    }
    public void OnDisable()
    {
        _isEnabled = false;
        //Deinitialize();
    }
    #endregion

    #region Signals
    private void SubscribeToSignals()
    {
        GameSignals.UPDATE_FOOD_ON_PLATE.AddListener(OnUpdateFoodOnPlateSignal);
    }
    private void UnsubscribeFromSignals()
    {
        GameSignals.UPDATE_FOOD_ON_PLATE.RemoveListener(OnUpdateFoodOnPlateSignal);
    }
    private void OnUpdateFoodOnPlateSignal(Frame p_frame, EntityRef p_etyPlate)
    {
        if (_entityRef != EntityRef.None && p_frame.Exists(_entityRef))
        {
            if (p_frame.Unsafe.TryGetPointer<AgentItemComponent>(_entityRef, out var cmpAgentItem))
            {
                if (cmpAgentItem->heldItemEntity == p_etyPlate)
                {
                    UpdatePlateHeldItemSkin(p_frame, p_etyPlate);
                }
            }
        }
    }
    #endregion

    #region Event Listeners
    private void SubscribeToQuantumEvents()
    {
        QuantumEvent.Subscribe<EventOnStatusActivatedEvent>(this, OnStatusActivatedEvent);
        QuantumEvent.Subscribe<EventOnStatusDeactivatedEvent>(this, OnStatusDeactivatedEvent);
        QuantumEvent.Subscribe<EventOnAgentHoldItem>(this, OnAgentHeldItemEvent);
        QuantumEvent.Subscribe<EventOnAgentRemoveHeldItem>(this, OnAgentRemoveHeldItem);
        QuantumEvent.Subscribe<EventOnInteractWithObject>(this, OnAgentInteractedWithObject);
        QuantumEvent.Subscribe<EventOnAgentSetCurrentAttackStateEvent>(this, OnAgentSetCurrentAttackState);
        QuantumEvent.Subscribe<EventOnSTPClearPlateEvent>(this, OnClearPlate);
        QuantumEvent.Subscribe<EventOnPlayerReconnectedEvent>(this, OnReconnect);
        QuantumEvent.Subscribe<EventOnStartDashEvent>(this, OnStartDash);
        QuantumEvent.Subscribe<EventOnEndDashEvent>(this, OnEndDash);
        QuantumEvent.Subscribe<EventSetCurrentWeaponEvent>(this, OnSetCurrentWeaponEvent);
        QuantumEvent.Subscribe<EventOnAgentMRDeathEvent>(this, OnAgentMRDeathEvent);
        QuantumEvent.Subscribe<EventOnAgentMRSpawnCorpseEvent>(this, OnAgentMRSpawnCorpseEvent);
        QuantumEvent.Subscribe<EventOnAgentMRRespawnEvent>(this, OnAgentMRRespawnEvent);
        QuantumEvent.Subscribe<EventOnAgentRemovedMRComponent>(this, OnAgentMRRemovedEvent);
    }
    private void UnsubscribeFromQuantumEvents()
    {
        QuantumEvent.UnsubscribeListener<EventOnStatusActivatedEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnStatusDeactivatedEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnAgentHoldItem>(this);
        QuantumEvent.UnsubscribeListener<EventOnAgentRemoveHeldItem>(this);
        QuantumEvent.UnsubscribeListener<EventOnInteractWithObject>(this);
        QuantumEvent.UnsubscribeListener<EventOnAgentSetCurrentAttackStateEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnSTPClearPlateEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnPlayerReconnectedEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnStartDashEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnEndDashEvent>(this);
        QuantumEvent.UnsubscribeListener<EventSetCurrentWeaponEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnAgentMRDeathEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnAgentMRSpawnCorpseEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnAgentMRRespawnEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnAgentRemovedMRComponent>(this);
    }
    private void OnStatusDeactivatedEvent(EventOnStatusDeactivatedEvent p_callback)
    {
        Frame frame = p_callback.frame;
        EntityRef etyAgent = p_callback.agentEntityRef;

        if (etyAgent == _entityRef)
        {
            switch (p_callback.status.statusType)
            {
                case STATUS.Knocked_Out:
                case STATUS.Stunned:
                    bool blnKnockedout = false;
                    if (frame.Unsafe.TryGetPointer<AgentStatusComponent>(etyAgent, out var cmpAgentStatus))
                    {
                        blnKnockedout = cmpAgentStatus->blnIsKnockedOut;
                    }
                    if (!blnKnockedout)
                    {
                        SetIsKnockedOut(false);
                    }
                    break;
                case STATUS.Invulnerable:
                    _sklamPlayer.skeleton.A = 1f;
                    _invulnerableTween.Pause();
                    break;
                default:
                    break;
            }
        }
    }

    private void OnStatusActivatedEvent(EventOnStatusActivatedEvent p_callback)
    {
        OnStatusActivated(p_callback.agentEntityRef, p_callback.status.statusType, true);
    }

    private unsafe void OnAgentHeldItemEvent(EventOnAgentHoldItem p_callback)
    {
        OnAgentHeldItem(p_callback.frame, p_callback.source, p_callback.heldItem);
    }

    private void OnAgentRemoveHeldItem(EventOnAgentRemoveHeldItem p_callback)
    {
        if (p_callback.source == _entityRef)
        {
            SetIsHoldingItem(false);
            RemoveHeldItemFromSkin();
        }
    }

    private void OnAgentInteractedWithObject(EventOnInteractWithObject p_callback)
    {
        if (_entityRef == p_callback.actorEntity)
        {
            if (p_callback.objType == INTERACTABLE_OBJECT_TYPE.Egg_Repository)
            {
                SetIsDepositing(true);
            }
        }
    }


    private void OnAgentSetCurrentAttackState(EventOnAgentSetCurrentAttackStateEvent p_callback)
    {
        if (p_callback.etyOwner == _entityRef)
        {
            if (p_callback.state == AGENT_ATTACK_STATE.Attack_Delay)
            { // Start of attack
                SetIsAttacking(true);
            }
            else if (p_callback.state == AGENT_ATTACK_STATE.None)
            { // End of attack
                SetIsAttacking(false);
            }
        }
    }

    private unsafe void OnClearPlate(EventOnSTPClearPlateEvent p_callback)
    {
        Frame frame = QuantumRunner.Default.Game.Frames.Predicted;
        if (frame != null)
        {
            AgentItemComponent* cmpAgentItem = frame.Unsafe.GetPointer<AgentItemComponent>(_entityRef);
            EntityRef etyOwner = p_callback.etyOwner;
            if (etyOwner == cmpAgentItem->heldItemEntity)
            {
                UpdatePlateHeldItemSkin(frame, cmpAgentItem->heldItemEntity);
            }
        }

    }
    private void OnReconnect(EventOnPlayerReconnectedEvent p_callback)
    {
        if (PlayerQuantumManager.Instance.IsMainPlayer(p_callback.agentEntityRef))
        {
            OnReconnectStatusUpdate(p_callback.frame);
            OnReconnectHeldItemUpdate(p_callback.frame);
            OnReconnectHeldWeaponUpdate(p_callback.frame);
        }
    }

    private void OnSetCurrentWeaponEvent(EventSetCurrentWeaponEvent p_callback)
    {
        if (p_callback.etyAgent == _entityRef)
        {
            OnSetCurrentWeapon(p_callback.frame, p_callback.aguidWeapon);
        }
    }

    private void OnAgentMRDeathEvent(EventOnAgentMRDeathEvent p_callback)
    {
        if (p_callback.etyAgent == _entityRef)
        {
            SetIsHurting(true);
        }
    }

    private void OnAgentMRSpawnCorpseEvent(EventOnAgentMRSpawnCorpseEvent p_callback)
    {
        if (p_callback.etyAgent == _entityRef)
        {
            SetIsHurting(false);
        }
    }

    private void OnAgentMRRespawnEvent(EventOnAgentMRRespawnEvent p_callback)
    {
        if (p_callback.etyAgent == _entityRef)
        {
            SetIsHurting(false);
        }
    }

    private void OnAgentMRRemovedEvent(EventOnAgentRemovedMRComponent p_callback)
    {
        if (p_callback.etyAgent == _entityRef)
        {
            SetIsHurting(false);
        }
    }

    #endregion

    #region General
    public void Initialize(EntityRef entityRef)
    {
        //_sklamPlayer.keepAnimatorStateOnDisable = true;
        CategorizeSkins();
        _entityRef = entityRef;
        _game = QuantumRunner.Default.Game;
        _invulnerableTween = DOTween.Sequence();
        _invulnerableTween.Append(DOTween.ToAlpha(() => _sklamPlayer.skeleton.GetColor(), c => _sklamPlayer.skeleton.SetColor(c), 1f, 0.1f));
        _invulnerableTween.Append(DOTween.ToAlpha(() => _sklamPlayer.skeleton.GetColor(), c => _sklamPlayer.skeleton.SetColor(c), 0.5f, 0.1f));
        _invulnerableTween.SetLoops(-1, LoopType.Yoyo);
        _invulnerableTween.Pause();
        _isInitialized = true;
        // //had to set sorting orders per player because if players with the same sorting order overlap, they start flickering.
        // meshRenderer.sortingOrder = QuantumRunner.Default.Game.PlayerIsLocal(playerRef) ? 20 - playerRef._index : playerRef._index;
        SubscribeToQuantumEvents();
        SubscribeToSignals();
        _sklamPlayerController = _sklamPlayer.GetComponent<PlayerController>();
        bone = _sklamPlayer.Skeleton.FindBone(boneName);
    }
    public void Deinitialize()
    {
        _isInitialized = false;
        UnsubscribeFromQuantumEvents();
        UnsubscribeFromSignals();
    }
    public void UpdateAnimation()
    {
        MovementAnimation();
    }

    // public void RandomizeSkin() {
    //     var skeleton = skeletonMecanim.Skeleton;
    //     var skeletonData = skeleton.Data;
    //     var mixAndMatchSkin = new Skin("random-skin");
    //     mixAndMatchSkin.AddSkin(skeletonData.FindSkin(headSkins.GetRandomElement(out headAccessoryIndex)));
    //     mixAndMatchSkin.AddSkin(skeletonData.FindSkin(eyeSkins.GetRandomElement(out eyeIndex)));
    //     mixAndMatchSkin.AddSkin(skeletonData.FindSkin(outfitSkins.GetRandomElement(out outfitIndex)));
    //     mixAndMatchSkin.AddSkin(skeletonData.FindSkin(legOutfitSkins.GetRandomElement(out legOutfitIndex)));
    //     mixAndMatchSkin.AddSkin(skeletonData.FindSkin(skinTones.GetRandomElement(out skinToneIndex)));
    //     mixAndMatchSkin.AddSkin(skeletonData.FindSkin(accessorySkins.GetRandomElement(out accessoryIndex)));
    //     skeleton.SetSkin(mixAndMatchSkin);
    //     skeleton.SetSlotsToSetupPose();
    //     skeletonMecanim.Update();
    // }
    public void UpdateSkinGivenData(AgentSkinData p_skinData)
    {
        MaccimaLogger.Log($"UpdateSkinGivenData of {_entityRef}");
        Skeleton skeleton = _sklamPlayer.Skeleton;
        SkeletonData skeletonData = skeleton.Data;
        Skin currentSkin = new Skin("random-skin");
        headAccessoryIndex = p_skinData.headAccessory;
        eyeIndex = p_skinData.eyeSkin;
        outfitIndex = p_skinData.outfitSkin;
        legOutfitIndex = p_skinData.legSkin;
        skinToneIndex = p_skinData.skinTone;
        accessoryIndex = p_skinData.accessorySkin;
        if (!headSkins.IsIndexInList(headAccessoryIndex)) { headAccessoryIndex = 0; }
        if (!eyeSkins.IsIndexInList(eyeIndex)) { eyeIndex = 0; }
        if (!outfitSkins.IsIndexInList(outfitIndex)) { outfitIndex = 0; }
        if (!legOutfitSkins.IsIndexInList(legOutfitIndex)) { legOutfitIndex = 0; }
        if (!skinTones.IsIndexInList(skinToneIndex)) { skinToneIndex = 0; }
        if (!accessorySkins.IsIndexInList(accessoryIndex)) { accessoryIndex = 0; }
        currentSkin.AddSkin(skeletonData.FindSkin(headSkins[headAccessoryIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(eyeSkins[eyeIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(outfitSkins[outfitIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(legOutfitSkins[legOutfitIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(skinTones[skinToneIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(accessorySkins[accessoryIndex]));
        skeleton.SetSkin(currentSkin);
        skeleton.SetSlotsToSetupPose();
        _sklamPlayer.LateUpdate();
    }
    private void AddHeldItemToSkin(string p_skinPath)
    {
        MaccimaLogger.Log($"Add Held item {p_skinPath} to {_entityRef}");
        var skeleton = _sklamPlayer.Skeleton;
        var skeletonData = skeleton.Data;
        Skin currentSkin = new Skin("random-skin");
        if (!headSkins.IsIndexInList(headAccessoryIndex)) { headAccessoryIndex = 0; }
        if (!eyeSkins.IsIndexInList(eyeIndex)) { eyeIndex = 0; }
        if (!outfitSkins.IsIndexInList(outfitIndex)) { outfitIndex = 0; }
        if (!legOutfitSkins.IsIndexInList(legOutfitIndex)) { legOutfitIndex = 0; }
        if (!skinTones.IsIndexInList(skinToneIndex)) { skinToneIndex = 0; }
        if (!accessorySkins.IsIndexInList(accessoryIndex)) { accessoryIndex = 0; }
        currentSkin.AddSkin(skeletonData.FindSkin(headSkins[headAccessoryIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(eyeSkins[eyeIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(outfitSkins[outfitIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(legOutfitSkins[legOutfitIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(skinTones[skinToneIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(accessorySkins[accessoryIndex]));

        //add held item
        currentSkin.AddSkin(skeletonData.FindSkin(p_skinPath));

        skeleton.SetSkin(currentSkin);
        skeleton.SetSlotsToSetupPose();
        _sklamPlayer.LateUpdate();
    }
    public void AddHeldItemToSkin(EntityRef p_etyHeldItem)
    {
        var frame = QuantumRunner.Default.Game.Frames.Verified;
        if (frame != null)
        {
            if (frame.Unsafe.TryGetPointer<ItemComponent>(p_etyHeldItem, out var cmpItem))
            {
                ItemData itemData = frame.FindAsset<ItemData>(cmpItem->itemData.Id);
                if (itemData.itemName == ITEM_NAME.Egg)
                {
                    if (frame.TryGet(p_etyHeldItem, out EggItemComponent eggItemComponent))
                    {
                        string skinPath = "ITEMS/BREAD";
                        switch (eggItemComponent.currentColor)
                        {
                            case COLOR.Red:
                                skinPath = "ITEMS/MEAT";
                                break;
                            case COLOR.Blue:
                                skinPath = "ITEMS/CAKE";
                                break;
                            case COLOR.Green:
                                skinPath = "ITEMS/FISH";
                                break;
                            case COLOR.Yellow:
                                skinPath = "ITEMS/BREAD";
                                break;
                        }
                        AddHeldItemToSkin(skinPath);
                    }
                }
                else if (itemData.itemName == ITEM_NAME.Flag)
                {
                    AddHeldItemToSkin("ITEMS/PAPER");
                }
                else if (itemData.itemName == ITEM_NAME.STP_Fish_Ingredient)
                {
                    AddHeldItemToSkin("ITEMS/FISH");
                }
                else if (itemData.itemName == ITEM_NAME.STP_Meat_Ingredient)
                {
                    AddHeldItemToSkin("ITEMS/MEAT");
                }
                else if (itemData.itemName == ITEM_NAME.STP_Plate)
                {
                    UpdatePlateHeldItemSkin(frame, p_etyHeldItem);
                }
            }
        }
    }
    public void AddHeldWeaponToSkin(Frame p_frame, AssetGuid p_aguidWeapon)
    {
        if (p_frame != null)
        {
            if (p_aguidWeapon != default)
            {
                WeaponData weaponData = p_frame.FindAsset<WeaponData>(p_aguidWeapon);
                if (weaponData is GunData)
                {
                    SetIsHoldingItem(true);
                    /*                        SetIsHoldingWeapon(true);*/
                    AddHeldItemToSkin("ITEMS/GUN");
                }
            }
        }
    }

    private void RemoveHeldItemFromSkin()
    {
        MaccimaLogger.Log($"Removed Held item from {_entityRef}");
        var skeleton = _sklamPlayer.Skeleton;
        var skeletonData = skeleton.Data;
        Skin currentSkin = new Skin("random-skin");
        if (!headSkins.IsIndexInList(headAccessoryIndex)) { headAccessoryIndex = 0; }
        if (!eyeSkins.IsIndexInList(eyeIndex)) { eyeIndex = 0; }
        if (!outfitSkins.IsIndexInList(outfitIndex)) { outfitIndex = 0; }
        if (!legOutfitSkins.IsIndexInList(legOutfitIndex)) { legOutfitIndex = 0; }
        if (!skinTones.IsIndexInList(skinToneIndex)) { skinToneIndex = 0; }
        if (!accessorySkins.IsIndexInList(accessoryIndex)) { accessoryIndex = 0; }
        currentSkin.AddSkin(skeletonData.FindSkin(headSkins[headAccessoryIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(eyeSkins[eyeIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(outfitSkins[outfitIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(legOutfitSkins[legOutfitIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(skinTones[skinToneIndex]));
        currentSkin.AddSkin(skeletonData.FindSkin(accessorySkins[accessoryIndex]));
        skeleton.SetSkin(currentSkin);
        skeleton.SetSlotsToSetupPose();
        _sklamPlayer.LateUpdate();
    }
    private void CategorizeSkins()
    {
        headSkins = new List<string>();
        eyeSkins = new List<string>();
        outfitSkins = new List<string>();
        legOutfitSkins = new List<string>();
        skinTones = new List<string>();
        accessorySkins = new List<string>();
        for (int i = 0; i < _sklamPlayer.skeleton.Data.Skins.Items.Length; i++)
        {
            Skin skin = _sklamPlayer.skeleton.Data.Skins.Items[i];
            if (skin.Name.Contains("Hair", StringComparison.InvariantCultureIgnoreCase))
            {
                headSkins.Add(skin.Name);
            }
            else if (skin.Name.Contains("Eyes", StringComparison.InvariantCultureIgnoreCase))
            {
                eyeSkins.Add(skin.Name);
            }
            else if (skin.Name.Contains("Outfits-Chest", StringComparison.InvariantCultureIgnoreCase))
            {
                outfitSkins.Add(skin.Name);
            }
            else if (skin.Name.Contains("Outfits-Legs", StringComparison.InvariantCultureIgnoreCase))
            {
                legOutfitSkins.Add(skin.Name);
            }
            else if (skin.Name.Contains("Skintone", StringComparison.InvariantCultureIgnoreCase))
            {
                skinTones.Add(skin.Name);
            }
            else if (skin.Name.Contains("Accessories - Head", StringComparison.InvariantCultureIgnoreCase))
            {
                accessorySkins.Add(skin.Name);
            }
        }
    }
    #endregion

    #region Status
    private void OnStatusActivated(EntityRef p_etyPlayer, STATUS p_statusType, bool p_doFlashEffect)
    {
        if (p_etyPlayer == _entityRef)
        {
            switch (p_statusType)
            {
                case STATUS.Knocked_Out:
                case STATUS.Stunned:
                    SetIsKnockedOut(true);
                    if (p_doFlashEffect)
                    {
                        if (PlayerQuantumManager.Instance.PlayerIsLocal(QuantumRunner.Default.Game.Frames.Verified, _entityRef))
                        {
                            // UIManager.Instance.ShowFlashEffect();
                            GameSignals.DO_CAMERA_SHAKE_FOR_PLAYER.Dispatch(_entityRef);
                        }
                    }
                    break;
                case STATUS.Invulnerable:
                    _sklamPlayer.skeleton.A = 1f;
                    _invulnerableTween.Restart();
                    _invulnerableTween.Play();
                    break;
                default:
                    break;
            }
        }
    }
    private void OnReconnectStatusUpdate(Frame p_frame)
    {
        if (_entityRef != EntityRef.None)
        {
            if (p_frame.Unsafe.TryGetPointer<AgentStatusComponent>(_entityRef, out var cmpAgentStatus))
            {
                for (int i = 0; i < cmpAgentStatus->statuses.Length; i++)
                {
                    Status status = cmpAgentStatus->statuses[i];
                    if (status.isActivated)
                    {
                        OnStatusActivated(_entityRef, status.statusType, false);
                    }
                }
            }
        }
    }
    #endregion

    #region Items
    private void OnAgentHeldItem(Frame p_frame, EntityRef p_etyPlayer, EntityRef p_etyHeldItem)
    {
        if (p_etyPlayer == _entityRef)
        {
            Frame frame = p_frame;
            if (frame.Unsafe.TryGetPointer<ItemComponent>(p_etyHeldItem, out var cmpItem))
            {
                SetIsHoldingItem(true);
                ItemData itemData = frame.FindAsset<ItemData>(cmpItem->itemData.Id);
                switch (itemData.itemName)
                {
                    case ITEM_NAME.Egg:
                        if (frame.TryGet(p_etyHeldItem, out EggItemComponent eggItemComponent))
                        {
                            string skinPath = "ITEMS/BREAD";
                            switch (eggItemComponent.currentColor)
                            {
                                case COLOR.Red:
                                    skinPath = "ITEMS/MEAT";
                                    break;
                                case COLOR.Blue:
                                    skinPath = "ITEMS/CAKE";
                                    break;
                                case COLOR.Green:
                                    skinPath = "ITEMS/FISH";
                                    break;
                                case COLOR.Yellow:
                                    skinPath = "ITEMS/BREAD";
                                    break;
                            }
                            AddHeldItemToSkin(skinPath);
                        }
                        break;
                    case ITEM_NAME.Flag:
                        AddHeldItemToSkin("ITEMS/PAPER");
                        break;
                    //case ITEM_NAME.STP_Fish_Ingredient:
                    //    AddHeldItemToSkin("ITEMS/FISH");
                    //    break;
                    //case ITEM_NAME.STP_Meat_Ingredient:
                    //    AddHeldItemToSkin("ITEMS/MEAT");
                    //    break;
                    case ITEM_NAME.STP_Fish_Ingredient:
                    case ITEM_NAME.STP_Meat_Ingredient:
                        UpdateFoodHeldItemSkin(frame, p_etyHeldItem);
                        break;
                    case ITEM_NAME.STP_Plate:
                        UpdatePlateHeldItemSkin(frame, p_etyHeldItem);
                        break;
                }
            }
        }
    }
    private void OnReconnectHeldItemUpdate(Frame p_frame)
    {
        if (_entityRef != EntityRef.None)
        {
            if (p_frame.Unsafe.TryGetPointer<AgentItemComponent>(_entityRef, out var cmpAgentItem))
            {
                if (cmpAgentItem->HasHeldItem(p_frame))
                {
                    OnAgentHeldItem(p_frame, _entityRef, cmpAgentItem->heldItemEntity);
                }
            }
        }
    }
    #endregion

    #region Weapon

    private unsafe void OnSetCurrentWeapon(Frame p_frame, AssetGuid p_aguidWeapon)
    {
        if (p_aguidWeapon != default)
        {
            SetIsHoldingItem(true);
            /*SetIsHoldingWeapon(true);*/
            AddHeldWeaponToSkin(p_frame, p_aguidWeapon);
        }
        else
        {
            SetIsHoldingItem(false);
            /*                SetIsHoldingWeapon(false);*/
            RemoveHeldItemFromSkin();
        }
    }

    private void OnReconnectHeldWeaponUpdate(Frame p_frame)
    {
        if (_entityRef != EntityRef.None)
        {
            if (p_frame.Unsafe.TryGetPointer<AgentWeaponComponent>(_entityRef, out var cmpAgentWeapon))
            {
                if (cmpAgentWeapon->HasCurrentWeapon())
                {
                    OnSetCurrentWeapon(p_frame, cmpAgentWeapon->aguidCurrentWeapon);
                }
            }
        }
    }
    #endregion

    #region Movement
    private void MovementAnimation()
    {
        if (_isInitialized && _isEnabled)
        {
            AgentMovementComponent* cmpAgentMovement = _game.Frames.Verified.Unsafe.GetPointer<AgentMovementComponent>(_entityRef);
            _sklamPlayer.skeleton.ScaleX = (float)cmpAgentMovement->fpAgentOrientationX;
            // Check if knocked out
            if (_blnIsKnockedOut || _blnIsDepositing || _blnIsAttacking)
            {
                return;
            }
            SetIsMoving(cmpAgentMovement->velocity.Magnitude.AsFloat > 0.1f);
        }
    }

    private void OnStartDash(EventOnStartDashEvent p_callback)
    {
        if (p_callback.etyAgent == _entityRef)
        {
            SetIsDashing(true);
        }
    }

    private void OnEndDash(EventOnEndDashEvent p_callback)
    {
        if (p_callback.etyAgent == _entityRef)
        {
            SetIsDashing(false);
        }
    }

    private void SetIsMoving(bool p_blnState)
    {
        if (_blnIsMoving != p_blnState)
        {
            if (p_blnState)
            {
                _fltCurrentIdleDelayValue = _fltIdleDelay;
                TransitionToMovingBase();
            }
            else
            {
                _fltCurrentIdleDelayValue -= Time.deltaTime;
                if (_fltCurrentIdleDelayValue <= 0f)
                {
                    _fltCurrentIdleDelayValue = 0f;
                    TransitionToIdleBase();
                }
                else
                {
                    return;
                }
            }
            _blnIsMoving = p_blnState;
        }
    }

    private void TransitionToIdleOrMoving()
    {
        if (_blnIsMoving)
        {
            TransitionToMovingBase();
        }
        else
        {
            TransitionToIdleBase();
        }
    }

    private void TransitionToMovingBase()
    {
        if (_blnIsHoldingItem)
        {
            //Player is running and holding item
            _sklamPlayer.AnimationState.SetAnimation(0, "a_running_holding", true);
        }
        else
        {
            //Player is running without holding item
            _sklamPlayer.AnimationState.SetAnimation(0, "a_running_default9", true);
        }
    }
    private void TransitionToIdleBase()
    {
        if (_blnIsHoldingItem)
        {
            //Player is in place/idle and holding item
            _sklamPlayer.AnimationState.SetAnimation(0, "a_idle_holding", true);
        }
        else
        {
            //Player is  without holding item
            _sklamPlayer.AnimationState.SetAnimation(0, "a_idle", true);
        }
    }

    private void SetIsHoldingItem(bool p_blnState)
    {
        if (_blnIsHoldingItem != p_blnState)
        {
            _blnIsHoldingItem = p_blnState;
            if (_blnIsHoldingItem || _blnIsHoldingWeapon)
            {
                if (_blnIsMoving)
                {
                    _sklamPlayer.AnimationState.SetAnimation(0, "a_running_holding", true);
                }
                else
                {
                    _sklamPlayer.AnimationState.SetAnimation(0, "a_idle_holding", true);
                }
            }
            else
            {
                if (_blnIsKnockedOut || _blnIsDepositing)
                {
                    return;
                }
                TransitionToIdleOrMoving();
            }
        }
    }

    private void SetIsDashing(bool p_blnState)
    {
        if (_blnIsDashing != p_blnState)
        {
            _blnIsDashing = p_blnState;
            if (_blnIsDashing)
            {
                if (_blnIsAttacking)
                {
                    return;
                }
                _sklamPlayer.AnimationState.SetAnimation(0, "a_dashing", true);
            }
            else
            {
                TransitionToIdleOrMoving();
            }
        }
    }
    private void SetIsDepositing(bool p_blnState)
    {
        if (_blnIsDepositing != p_blnState)
        {
            _blnIsDepositing = p_blnState;
            if (_blnIsDepositing)
            {
                // Set deposit animation
                OnDoingDeposit();
                _sklamPlayer.AnimationState.SetAnimation(0, "a_deposit", false).Complete += StopDepositing;
            }
            else
            {
                OnDepositDone();
                TransitionToIdleOrMoving();
            }
        }
    }

    private void StopDepositing(TrackEntry p_tEntry)
    {
        SetIsDepositing(false);
    }
    private void SetIsHurting(bool p_blnState)
    {
        _blnIsHurting = p_blnState;
        if (_blnIsHurting)
        {
            _sklamPlayer.AnimationState.SetAnimation(0, "a_hurt", true);
        }
        else
        {
            TransitionToIdleOrMoving();
        }
    }

    private void SetIsKnockedOut(bool p_blnState)
    {
        if (_blnIsKnockedOut != p_blnState)
        {
            _blnIsKnockedOut = p_blnState;
            if (_blnIsKnockedOut)
            {
                SetIsDepositing(false);
                _sklamPlayer.AnimationState.SetAnimation(0, "a_knockedout", true);
            }
            else
            {
                TransitionToIdleOrMoving();
            }
        }
    }

    private void SetIsAttacking(bool p_blnState)
    {
        if (_blnIsAttacking != p_blnState)
        {
            _blnIsAttacking = p_blnState;
            if (_blnIsAttacking)
            {
                TrackEntry entry = _sklamPlayer.AnimationState.SetAnimation(0, "a_attack2", false);
                entry.TimeScale = 2;
            }
            else
            {
                if (_blnIsKnockedOut)
                {
                    return;
                }
                TransitionToIdleOrMoving();
            }
        }
    }

/* private void SetIsHoldingWeapon(bool p_blnState)
{
if (_blnIsHoldingWeapon != p_blnState)
{
blnIsHoldingWeapon = p_blnState;
if (
blnIsHoldingWeapon)
{
_sklamPlayer.AnimationState.SetAnimation(0, "aim_gun", true);
}
else
{
TransitionToIdleOrMoving();
}
}
}*/

    public void Update()
    {
        if (_blnIsHoldingItem)
        {
            if (_sklamPlayerController == null)
                _sklamPlayerController = GetComponent<PlayerController>();


            bone.SetPositionSkeletonSpace(_sklamPlayerController.GetLastAimPosition());
        }
    }

    #endregion

    #region Deposit
    public void OnDoingDeposit()
    {
        if (PlayerQuantumManager.Instance.PlayerIsLocal(QuantumRunner.Default.Game.Frames.Verified, _entityRef))
        {
            GameSignals.SET_MOVEMENT_STATE.Dispatch(_entityRef, false);
        }
    }
    public void OnDepositDone()
    {
        if (PlayerQuantumManager.Instance.PlayerIsLocal(QuantumRunner.Default.Game.Frames.Verified, _entityRef))
        {
            GameSignals.SET_MOVEMENT_STATE.Dispatch(_entityRef, true);
        }
    }
    #endregion

    #region Serve The Poor
    private unsafe void UpdateFoodHeldItemSkin(Frame p_frame, EntityRef p_etyHeldItem)
    {
        EntityRef etySTPManager = p_frame.Unsafe.GetPointerSingleton<MainGameManager>()->etySTPMainManager;
        if (etySTPManager == default)
        {
            //AddHeldItemToSkin($"ITEMS/{p_strDefaultSkinName}");
            return;
        }
        STPMainManager* cmpSTPMainManager = p_frame.Unsafe.GetPointer<STPMainManager>(etySTPManager);
        STPIngredientComponent* cmpIngredient = p_frame.Unsafe.GetPointer<STPIngredientComponent>(p_etyHeldItem);
        STPFoodItemData foodData = cmpSTPMainManager->GetFoodItemDataThatMatchIngredient(p_frame, cmpIngredient->ingredient);
        if (foodData != null)
        {

            AddHeldItemToSkin($"ITEMS/{foodData.strSkinNameInAgentWithoutPlate}");
        }
        else
        {
            LaborMinigameDBData laborMinigameDB = p_frame.FindAsset<LaborMinigameDBData>(p_frame.RuntimeConfig.laborMinigameDB.Id);
            AssetRefLaborMinigameData arefSTP = laborMinigameDB.GetLaborMinigameData(p_frame, LABOR_MINIGAME.Serve_The_Poor);
            ServeThePoorMinigameDataAsset assetSTP = UnityDB.FindAsset<ServeThePoorMinigameDataAsset>(arefSTP.Id);
            string strSkinName = assetSTP.GetSTPIngredientSkinName(cmpIngredient->ingredient);
            if (!string.IsNullOrEmpty(strSkinName))
            {
                AddHeldItemToSkin($"ITEMS/{strSkinName}");
            }
            //else {
            //    AddHeldItemToSkin($"ITEMS/{p_strDefaultSkinName}");
            //}
            //for (int i = 0; i < cmpIngredient->recipeOnPlate.arrIngredients.Length; i++) {
            //    STPIngredient ingredient = cmpIngredient->recipeOnPlate.arrIngredients[i];
            //    if (ingredient.ingredient == STP_INGREDIENT.Fish) {
            //        if (ingredient.cuttingMethod == STP_CUTTING_METHOD.Mashed) {
            //            AddHeldItemToSkin("ITEMS/PLATE_MASHFISH");
            //        } else {
            //            AddHeldItemToSkin("ITEMS/PLATE_FISH");
            //        }
            //        isEmpty = false;
            //        break;
            //    } else if (ingredient.ingredient == STP_INGREDIENT.Meat) {
            //        AddHeldItemToSkin("ITEMS/PLATE_MEAT");
            //        isEmpty = false;
            //        break;
            //    }
            //}
        }
    }
    private unsafe void UpdatePlateHeldItemSkin(Frame p_frame, EntityRef p_etyHeldItem)
    {
        STPPlateComponent* cmpPlate = p_frame.Unsafe.GetPointer<STPPlateComponent>(p_etyHeldItem);
        bool isEmpty = true;
        if (cmpPlate->aguidFoodOnPlate != default)
        {
            STPFoodItemData foodOnPlate = p_frame.FindAsset<STPFoodItemData>(cmpPlate->aguidFoodOnPlate);
            AddHeldItemToSkin($"ITEMS/{foodOnPlate.strSkinNameInAgentWithPlate}");
            isEmpty = false;
            Debug.Log("UPDATE PLATE: " + foodOnPlate.strSkinNameInAgentWithPlate);
        }
        //else {
        //    for (int i = 0; i < cmpPlate->recipeOnPlate.arrIngredients.Length; i++) {
        //        STPIngredient ingredient = cmpPlate->recipeOnPlate.arrIngredients[i];
        //        if (ingredient.ingredient == STP_INGREDIENT.Fish) {
        //            if (ingredient.cuttingMethod == STP_CUTTING_METHOD.Mashed) {
        //                AddHeldItemToSkin("ITEMS/PLATE_MASHFISH");
        //            } else {
        //                AddHeldItemToSkin("ITEMS/PLATE_FISH");
        //            }
        //            isEmpty = false;
        //            break;
        //        } else if (ingredient.ingredient == STP_INGREDIENT.Meat) {
        //            AddHeldItemToSkin("ITEMS/PLATE_MEAT");
        //            isEmpty = false;
        //            break;
        //        }
        //    }
        //}
        if (isEmpty)
        {
            if (cmpPlate->blnIsDirty)
            {
                AddHeldItemToSkin("ITEMS/PLATE_EMPTY");
            }
            else
            {
                AddHeldItemToSkin("ITEMS/PLATE_CLEAN");
            }
        }
    }
    #endregion
}

}

What I did is that I call out another function from another script for the aiming but Im not sure if I'm correct:
using System.Collections.Generic;
using System.Linq;
using EatTheRich.UI;
using EatTheRich.Utilities;
using Photon.Deterministic;
using Quantum;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.UI;
using UnityEngine.InputSystem.Users;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.InputSystem.XR;
using UnityEngine.Serialization;
using UnityEngine.UIElements;

namespace EatTheRich {
[RequireComponent(typeof(PlayerInput))]
public class PlayerController : MonoBehaviour {
public PlayerInput playerInput;
[FormerlySerializedAs("unityPlayerAgentComponent")] public UnityAgentComponent unityAgentComponent;

    #region Private Properties
    private bool _isInitialized;
    private PlayerRef _playerRef;
    private EntityRef _entityRef;
    private InteractWithObjectCommand _interactCommand;
    private DropHeldItemCommand _dropHeldItemCommand;
    private DashCommand _dashCommand;
    private int _gameplayMapDisabledVotes;
    private int _radialMenuDisabledVotes;
    private Vector2 _vecLastAimDirection;
    #endregion

    #region Inputs
    private bool _blnIsMoving;
    private bool _blnIsUsingGamepad;
    private bool _blnCanPlayerMove;
    private bool _blnHasWeapon;
    private Dictionary<string, InputAction> _dicInputActions;
    private InputDevice _assignedInputDevice;
    //private InputAction _movementAction;
    //private InputAction _interactAction;
    //private InputAction _dropAction;
    //private InputAction _attackAction;
    //private InputAction _mousePositionAction;
    //private InputAction _aimGamepadAction;
    #endregion

    #region getters
    //Needed to change GetBindingDisplayString to bindings[0].ToDisplayString(options: InputBinding.DisplayStringOptions.DontIncludeInteractions)
    //because of issue with different languages: https://trello.com/c/ye2rgrfv/796-control-icons-issue
    //Reference: https://forum.unity.com/threads/getbindingdisplaystring-returns-non-english-names-when-the-players-keyboard-is-set-to-non-english.1263992/
    public string interactKeybindingDisplay {
        get {
            InputAction inputAction = GetInputAction("Interact");
            return InputManager.Instance.GetTextIconRichTextForControl(playerInput,
                inputAction.bindings.ElementAtOrDefault(inputAction.GetBindingIndex(playerInput.currentControlScheme)).ToDisplayString(options: InputBinding.DisplayStringOptions.DontIncludeInteractions));
        }
    }
    public string dropKeybindingDisplay {
        get {
            InputAction inputAction = GetInputAction("Drop Item");
            return InputManager.Instance.GetTextIconRichTextForControl(playerInput,
                inputAction.bindings.ElementAtOrDefault(inputAction.GetBindingIndex(playerInput.currentControlScheme)).ToDisplayString(options: InputBinding.DisplayStringOptions.DontIncludeInteractions));
        }
    }
    public string attackKeybindingDisplay {
        get {
            InputAction inputAction = GetInputAction("Attack");
            return InputManager.Instance.GetTextIconRichTextForControl(playerInput,
                inputAction.bindings.ElementAtOrDefault(inputAction.GetBindingIndex(playerInput.currentControlScheme)).ToDisplayString(options: InputBinding.DisplayStringOptions.DontIncludeInteractions));
        }
    }
    public string dashKeybindingDisplay {
        get {
            InputAction inputAction = GetInputAction("Dash");
            return InputManager.Instance.GetTextIconRichTextForControl(playerInput,
                inputAction.bindings.ElementAtOrDefault(inputAction.GetBindingIndex(playerInput.currentControlScheme)).ToDisplayString(options: InputBinding.DisplayStringOptions.DontIncludeInteractions));
        }
    }
    public string stpActionKeybindingDisplay {
        get {
            InputAction inputAction = GetInputAction("STP Action");
            return InputManager.Instance.GetTextIconRichTextForControl(playerInput,
                inputAction.bindings.ElementAtOrDefault(inputAction.GetBindingIndex(playerInput.currentControlScheme)).ToDisplayString(options: InputBinding.DisplayStringOptions.DontIncludeInteractions));
        }
    }
    public string spectateShortcut {
        get {
            if (playerInput.currentControlScheme == "Keyboard") {
                return "TAB";
            } else if (playerInput.currentControlScheme == "Gamepad") {
                return "RIGHT-STICK CLICK";
            }
            return string.Empty;
        }
    }
    public bool isUsingGamepad => _blnIsUsingGamepad;
    #endregion

    /// <summary>
    /// Initialize this Player Controller instance.
    /// This only happens for local players.
    /// </summary>
    public void Initialize(PlayerRef p_playerRef, EntityRef p_entityRef) {
        _isInitialized = true;
        _blnCanPlayerMove = true;
        _playerRef = p_playerRef;
        _entityRef = p_entityRef;
        //_movementAction = playerInput.actions.FindAction("Movement");
        //_interactAction = playerInput.actions.FindAction("Interact");
        //_dropAction = playerInput.actions.FindAction("Drop Item");
        //_attackAction = playerInput.actions.FindAction("Attack");
        //_mousePositionAction = playerInput.actions.FindAction("MousePosition");
        //_aimGamepadAction = playerInput.actions.FindAction("Aim");
        _interactCommand = new InteractWithObjectCommand();
        _dropHeldItemCommand = new DropHeldItemCommand();
        _dashCommand = new DashCommand();
        InitializeInputs();
        EnableInputActionMap("UI");
        // InputManager.Instance.SwitchUIControlToThis(playerInput);
        AssignControlDeviceToThisPlayer();
        SubscribeCsharpEvents();
        SubscribeToSignals();
        SubscribeToEvents();
        InputManager.Instance.AddPlayerController(p_playerRef, this);
    }

    #region Monobehaviours
    private void Update() {
        if (_blnIsUsingGamepad) {
            if (_blnHasWeapon) {
                GameObject goGamepadCrosshairVisual = unityAgentComponent.goGamepadCrosshairVisual;
                goGamepadCrosshairVisual.transform.position = GetLastAimPosition();
            }
        }
    }
    private void OnDestroy() {
        UnsubscribeCsharpEvents();
        UnsubscribeToSignals();
        UnsubscribeFromEvents();
    }
    #endregion
    
    #region General
    public void SetEnabledState(bool p_state) {
        enabled = p_state;
        playerInput.enabled = p_state;
        if (p_state) {
            playerInput.ActivateInput();
        } else {
            playerInput.DeactivateInput();
        }
    }
    private void AssignControlDeviceToThisPlayer() {
        int[] localPlayerIndexes = QuantumRunner.Default.Game.GetLocalPlayers();
        if (localPlayerIndexes.Length > 1) {
            if (PlayerQuantumManager.Instance.assignControlDevicesToNonMainPlayers) {
                //there is more than 1 local player, assign devices accordingly
                playerInput.neverAutoSwitchControlSchemes = true;
                int indexInLocalPlayers = -1;
                for (int i = 0; i < localPlayerIndexes.Length; i++) {
                    if (localPlayerIndexes[i] == _playerRef) {
                        indexInLocalPlayers = i;
                        break;
                    }
                }
                MaccimaLogger.AssertIsTrue(indexInLocalPlayers != -1);
                
                if (Gamepad.all.Count >= localPlayerIndexes.Length) {
                    //assign gamepad to each player
                    Gamepad gamepad = Gamepad.all[indexInLocalPlayers];
                    AssignGamepadToThisUser(gamepad);
                    if (indexInLocalPlayers == 0) {
                        //assign keyboard to first player as well
                        InputUser.PerformPairingWithDevice(Keyboard.current, playerInput.user);
                        InputUser.PerformPairingWithDevice(Mouse.current, playerInput.user);
                        MaccimaLogger.Log($"Assigned keyboard and mouse to {_playerRef}.");
                    }
                } else {
                    if (indexInLocalPlayers == 0) {
                        //assign keyboard to first player
                        SetEnabledState(true);
                        playerInput.SwitchCurrentControlScheme(Keyboard.current, Mouse.current);
                        MaccimaLogger.Log($"Assigned keyboard to {_playerRef}");
                        _assignedInputDevice = Keyboard.current;
                        SetIsUsingGamepad(false);
                    } else {
                        //assign player to an available controller
                        int gamePadIndex = indexInLocalPlayers - 1;
                        if (Gamepad.all.Count > gamePadIndex) {
                            Gamepad gamepad = Gamepad.all[gamePadIndex];
                            AssignGamepadToThisUser(gamepad);
                        } else {
                            _assignedInputDevice = null;
                            SetEnabledState(false);
                            MaccimaLogger.LogWarning($"Was unable to assign a device to player {_playerRef}. Deactivating it for now.");
                        }
                    }    
                }
            } else {
                //disable control of other local players
                if (PlayerQuantumManager.Instance.IsMainPlayer(_playerRef)) {
                    SetEnabledState(true);
                    playerInput.neverAutoSwitchControlSchemes = false;        
                } else {
                    _assignedInputDevice = null;
                    SetEnabledState(false);
                }
            }
        } else {
            SetEnabledState(true);
            //if there is only 1 local player, allow them to switch control devices on the fly.
            playerInput.neverAutoSwitchControlSchemes = false;
        }
    }
    private void AssignGamepadToThisUser(Gamepad p_gamepad) {
        SetEnabledState(true);
        playerInput.SwitchCurrentControlScheme(p_gamepad);
        MaccimaLogger.Log($"Assigned gamepad {p_gamepad.displayName} to {_playerRef}");
        _assignedInputDevice = p_gamepad;
        SetIsUsingGamepad(true);
    }
    private void SetGameplayInputStateForLocalPlayers(bool p_state) {
        if (QuantumRunner.Default?.Game != null && QuantumRunner.Default.Game.PlayerIsLocal(_playerRef)) {
            SetGameplayInputState(p_state);
        }
    }
    private void SetGameplayInputState(EntityRef p_etyAgent, bool p_state) {
        if (p_etyAgent == _entityRef) {
            SetGameplayInputState(p_state);
        }
    }
    private void SetGameplayInputState(bool p_state) {
        if (p_state) {
            _gameplayMapDisabledVotes--;
        } else {
            _gameplayMapDisabledVotes++;
        }
        MaccimaLogger.Log($"{_playerRef} Updated Gameplay input disable votes: {_gameplayMapDisabledVotes}");
        UpdateGameplayInputState();
    }
    private void UpdateGameplayInputState() {
        if (_gameplayMapDisabledVotes > 0) {
            playerInput.actions.FindActionMap("Gameplay").Disable();
        } else {
            playerInput.actions.FindActionMap("Gameplay").Enable();
        }
    }
    private void SetMovementInputState(EntityRef p_playerRef, bool p_state) {
        if (p_playerRef == _entityRef) {
            if (p_state) {
                EnableMovement();
            } else {
                DisableMovement();
            }    
        }
    }
    private void EnableMovement() {
        _blnCanPlayerMove = true;
    }
    private void DisableMovement() {
        _blnCanPlayerMove = false;
    }
    private void OnSetCurrentJobStatus(AGENT_JOB_STATUS p_status) {
        if (p_status == AGENT_JOB_STATUS.Invited_Laborer || p_status == AGENT_JOB_STATUS.Laborer) {
            EnableInputActionMap("Labor");
        } else {
            DisableInputActionMap("Labor");
        }
    }
    #endregion

    #region Inputs
    private void InitializeInputs() {
        _dicInputActions = new Dictionary<string, InputAction>();
        InputActionMap gameplayInputActionMap = playerInput.actions.FindActionMap("Gameplay");
        InputAction[] arrGameplayActions = gameplayInputActionMap.actions.ToArray();
        for (int i = 0; i < arrGameplayActions.Length; i++) {
            InputAction inpAction = arrGameplayActions[i];
            _dicInputActions.Add(inpAction.name, inpAction);
        }

        InputActionMap laborInputActionMap = playerInput.actions.FindActionMap("Labor");
        InputAction[] arrLaborActions = laborInputActionMap.actions.ToArray();
        for (int i = 0; i < arrLaborActions.Length; i++) {
            InputAction inpAction = arrLaborActions[i];
            _dicInputActions.Add(inpAction.name, inpAction);
        }
    }
    public InputAction GetInputAction(string p_strInputName) {
        if (_dicInputActions.ContainsKey(p_strInputName)) {
            return _dicInputActions[p_strInputName];
        }
        return null;
    }
    private void EnableInputActionMap(string p_strActionMapName) {
        playerInput.actions.FindActionMap(p_strActionMapName)?.Enable();
    }
    private void DisableInputActionMap(string p_strActionMapName) {
        playerInput.actions.FindActionMap(p_strActionMapName)?.Disable();
    }
    private void SubscribeCsharpEvents() {
        InputSystem.onDeviceChange += OnDeviceChanged;
        playerInput.onActionTriggered += OnActionTriggered;
        playerInput.onControlsChanged += OnControlsChanged;
    }
    private void UnsubscribeCsharpEvents() {
        InputSystem.onDeviceChange -= OnDeviceChanged;
        playerInput.onActionTriggered -= OnActionTriggered;
        playerInput.onControlsChanged -= OnControlsChanged;
    }
    private void OnDeviceChanged(InputDevice p_device, InputDeviceChange p_change) {
        if (p_change == InputDeviceChange.Added || p_change == InputDeviceChange.Removed) {
            AssignControlDeviceToThisPlayer();
        }
    }
    private void OnControlsChanged(PlayerInput p_playerInput) {
        MaccimaLogger.Log($"{_playerRef} Changed controls to {p_playerInput.currentControlScheme}");
        SetIsUsingGamepad(p_playerInput.currentControlScheme != "Keyboard");
        GameSignals.PLAYER_CHANGED_CONTROLS.Dispatch(_playerRef, p_playerInput, this);
    }
    private void OnActionTriggered(InputAction.CallbackContext obj) {
        if (!InputManager.Instance.isApplicationFocused) { return; }
        switch (obj.action.name) {
            case "Interact":
                if (obj.performed) { Interact(obj); }
                break;
            case "Switch Spectate":
                if (obj.performed) { SwitchSpectate(obj); }
                break;
            case "Drop Item":
                if (obj.performed) { DropItem(obj); }
                break;
            //case "Attack":
            //    if (obj.performed) { AttackAgent(obj); }
            //    break;
            case "Dash":
                if (obj.performed) { DashAgent(obj); }
                break;
            case "Movement":
                if (obj.started) {
                    OnMovementStarted(obj);
                } else if (obj.canceled) {
                    OnMovementCanceled(obj);
                }
                break;
            case "Toggle Debug Info":
                if (obj.performed) { ToggleDebugInfo(obj); }
                break;
            case "Toggle Settings":
                if (obj.performed) { ToggleSettings(obj); }
                break;
            case "Toggle Radial Menu":
                if (obj.performed) { ToggleRadialMenu(obj); }
                break;
        }
        if (obj.performed) {
            GameSignals.INPUT_ACTION_PERFORMED.Dispatch(obj, obj.action);
        } else if (obj.started) {
            GameSignals.INPUT_ACTION_STARTED.Dispatch(obj, obj.action);
        } else if (obj.canceled) {
            GameSignals.INPUT_ACTION_CANCELED.Dispatch(obj, obj.action);
        }
    }
    private void OnMovementStarted(InputAction.CallbackContext p_obj) {
        SetIsMoving(true);
    }
    private void OnMovementCanceled(InputAction.CallbackContext p_obj) {
        SetIsMoving(false);
    }
    private void Interact(InputAction.CallbackContext p_obj) {
        if (unityAgentComponent.nearestInteractable != default) {
            _interactCommand.actor = _playerRef;
            _interactCommand.target = unityAgentComponent.nearestInteractable;
            _interactCommand.actorEntity = _entityRef;
            QuantumRunner.Default.Game.SendCommand(_interactCommand);
        }    
    }
    private void SwitchSpectate(InputAction.CallbackContext p_obj) {
        if (p_obj.performed && enabled) {
            if (PlayerQuantumManager.Instance.IsMainPlayer(_playerRef)) {
                unityAgentComponent.SwitchSpectate();    
            }
        }
    }
    private void DropItem(InputAction.CallbackContext p_obj) {
        if (p_obj.performed && enabled) {
            _dropHeldItemCommand.actor = _playerRef;
            _dropHeldItemCommand.actorEntity = _entityRef;
            QuantumRunner.Default.Game.SendCommand(_dropHeldItemCommand);
        }
    }
    private unsafe void DashAgent(InputAction.CallbackContext p_obj) {
        if (p_obj.performed && enabled && _blnCanPlayerMove) {
            _dashCommand.etyDasher = _entityRef;
            QuantumRunner.Default.Game.SendCommand(_dashCommand);
            //Frame frame = QuantumRunner.Default.Game.Frames.Verified;
            //if (frame != null) {
                //if (frame.Unsafe.TryGetPointer<AgentMovementComponent>(_entityRef, out var cmpAgentMovement)) {
                //    if (!cmpAgentMovement->blnIsDashing) {
                //        _dashCommand.etyDasher = _entityRef;
                //        QuantumRunner.Default.Game.SendCommand(_dashCommand);
                //    }
                //}
            //}
        }
    }
    private void ToggleDebugInfo(InputAction.CallbackContext p_obj) {
        if (p_obj.performed) {

#if DEVELOPMENT_BUILD UNITY_EDITOR
var debugUI = FindObjectOfType<DebugUI>();
debugUI?.SetIsEnabled(!debugUI.isEnabled);
#endif
}
}
private void ToggleSettings(InputAction.CallbackContext p_obj) {
if (p_obj.performed) {
SettingsManager.Instance.ToggleSettingsMenu();
}
}
private unsafe void ToggleRadialMenu(InputAction.CallbackContext p_obj) {
if (p_obj.performed) {
var frame = QuantumRunner.Default?.Game?.Frames?.Verified;
if (frame != null) {
if (frame.Global->gameStateManager.currentGameState == GAME_STATE.Lobby
frame.Global->gameStateManager.currentGameState == GAME_STATE.Game_Over) { return; }
if (frame.Global->phaseManager.currentPhaseState != PHASE_STATE.Actual) { return; }
if (frame.Global->phaseManager.currentPhase.phase == PHASE.Transition frame.Global->phaseManager.currentPhase.phase == PHASE.Elimination_Result
frame.Global->phaseManager.currentPhase.phase == PHASE.Game_Proper_Transition frame.Global->phaseManager.currentPhase.phase == PHASE.Results
frame.Global->phaseManager.currentPhase.phase == PHASE.Voting || frame.Global->phaseManager.currentPhase.phase == PHASE.Voting_Result) { return; }
AgentComponent* ac = PlayerAndAgentUtilities.GetAgentComponent(frame, _playerRef);
if (ac->isEliminated) { return; }
}
if (UIManager.Instance.radialMenuUIController.IsAnyRadialMenuShowing()) {
UIManager.Instance.radialMenuUIController.CloseAllRadialMenus();
} else {
UIManager.Instance.radialMenuUIController.EnableRadialMenu("PlayerActionsMenu");
}
}
}
public void SetIsMoving(bool p_state) {
_blnIsMoving = p_state;
}
public void SetIsUsingGamepad(bool p_state) {
_blnIsUsingGamepad = p_state;
UpdaateGamepadCursor();

    }
    public void SetHasWeapon(bool p_state) {
        _blnHasWeapon = p_state;
        UpdaateGamepadCursor();
    }
    private void UpdaateGamepadCursor() {
        if (PlayerQuantumManager.Instance.PlayerIsLocal(QuantumRunner.Default?.Game?.Frames?.Verified, _entityRef)) {
            if (_blnHasWeapon) {
                InputManager.Instance.SetCursorToReticle();
            } else {
                InputManager.Instance.SetCursorToDefault();
            }
            if (_blnIsUsingGamepad) {
                if (InputManager.Instance.AreAllPlayersUsingGamepad()) {
                    InputManager.Instance.HideCursor();    
                }
                if (_blnHasWeapon) {
                    unityAgentComponent.ShowGamepadCrosshairCursorVisual();
                } else {
                    unityAgentComponent.HideGamepadCrosshairCursorVisual();
                }
            } else {
                InputManager.Instance.ShowCursor();
                unityAgentComponent.HideGamepadCrosshairCursorVisual();
            }
        }
    }
    public bool IsPressedInputActionButton(string p_strInputName) {
        if (!enabled) {
            return false;
        }
        if (UIManager.Instance.IsMouseOverUI && p_strInputName == "Attack" && playerInput.currentControlScheme == "Keyboard") {
            return false;
        }
        //InputAction inpAction = GetInputAction(p_strInputName);
        //string strDisplay = inpAction.GetBindingDisplayString(options: InputBinding.DisplayStringOptions.DontIncludeInteractions);
        //Debug.Log(strDisplay);
        return GetInputAction(p_strInputName).IsPressed();
    }
    public FPVector2 GetMovementDirection() {
        if (!enabled) {
            return FPVector2.Zero;
        }
        if (!InputManager.Instance.isApplicationFocused) {
            return FPVector2.Zero;
        }
        if (_blnIsMoving && _blnCanPlayerMove) {
            return GetInputAction("Movement").ReadValue<Vector2>().ToFPVector2();
        }
        return FPVector2.Zero;
    }
    public FP GetAimAngle() {
        if (!enabled) {
            return 0;
        }
        if (_blnHasWeapon) {
            Vector2 vecMousePos = GetInputAction("Aim Weapon").ReadValue<Vector2>();
            if (_blnIsUsingGamepad) {
                if (vecMousePos != default) {
                    _vecLastAimDirection = vecMousePos;
                }
            } else {
                Vector3 vecMouseWorldPos = unityAgentComponent.playerCamera.ScreenToWorldPoint(vecMousePos);
                //vecMousePos = _mousePositionAction.ReadValue<Vector2>();
                //Vector3 vecMouseWorldPos = unityAgentComponent.playerCamera.ScreenToWorldPoint(vecMousePos);
                _vecLastAimDirection = vecMouseWorldPos - transform.position;
            }
            float fltAngle = Mathf.Atan2(_vecLastAimDirection.y, _vecLastAimDirection.x);
            fltAngle = Mathf.Repeat((fltAngle + 2 * Mathf.PI), 2 * Mathf.PI);
            return FP.FromFloat_UNSAFE(fltAngle);
        }
        return 0;
    }
    public Vector2 GetLastAimPosition() {
        if (!enabled) {
            return Vector2.zero;
        }
        if (_blnHasWeapon) {
            Vector2 vecAimPos = Vector2.zero;
            if (_blnIsUsingGamepad) {
                //float angle1 = Mathf.Atan2(-0.04f, 0.11f) * Mathf.Rad2Deg;
                //float angle2 = Mathf.Atan2(-0.04f, 0.40f) * Mathf.Rad2Deg;

                //Quaternion qua1 = Quaternion.Euler(0f, 0f, angle1 - 90);
                //Quaternion qua2 = Quaternion.Euler(0f, 0f, angle2 - 90);

                //Debug.Log("Angle 1: " + qua1.z);
                //Debug.Log("Angle 2: " + qua2.z);
                //float fltAngle = Mathf.Atan2(_vecLastAimDirection.y, _vecLastAimDirection.x);
                float fltAngle = Mathf.Atan2(_vecLastAimDirection.y, _vecLastAimDirection.x) * Mathf.Rad2Deg;
                Quaternion quat = Quaternion.Euler(0f, 0f, fltAngle - 90);
                Vector3 forw = quat * Vector3.up;
                //Vector3 vecTargetPos = new Vector3(Mathf.Cos(fltAngle), Mathf.Sin(fltAngle), 0f); //* (float) unityAgentComponent.fltGamepadAimCursorRadius;
                //Debug.Log("Angle 1: " + vecTargetPos);
                //Debug.Log("Angle 2: " + fltAngle);

                //float fltAngle2 = Mathf.Atan2(_vecLastAimDirection.y, _vecLastAimDirection.x);
                //fltAngle2 = Mathf.Repeat((fltAngle2 + 2 * Mathf.PI), 2 * Mathf.PI);

                //Debug.Log("Angle 3: " + fltAngle2);
                vecAimPos = transform.position + (forw * unityAgentComponent.fltGamepadAimCursorRadius);
                //vecAimPos = (_vecLastAimDirection * unityAgentComponent.fltGamepadAimCursorRadius) + new Vector2(transform.position.x, transform.position.y);
            } else {
                vecAimPos = _vecLastAimDirection;
            }
            return vecAimPos;
        }
        return Vector2.zero;
    }
    private void SetRadialMenuInputState(bool p_state) {
        if (p_state) {
            _radialMenuDisabledVotes--;
        } else {
            _radialMenuDisabledVotes++;
        }
        MaccimaLogger.Log($"{_playerRef} Updated Radial Menu input disable votes: {_radialMenuDisabledVotes}");
        UpdateRadialMenuInputState();
    }
    private void UpdateRadialMenuInputState() {
        if (_gameplayMapDisabledVotes > 0) {
            if (UIManager.Instance.radialMenuUIController.IsAnyRadialMenuShowing()) {
                UIManager.Instance.radialMenuUIController.CloseAllRadialMenus();
            }
            playerInput.actions.FindAction("Toggle Radial Menu").Disable();
        } else {
            playerInput.actions.FindAction("Toggle Radial Menu").Enable();
        }
    }
    #endregion

    #region Signals
    private void SubscribeToSignals() {
        MaccimaLogger.Log($"{_playerRef} subscribed to signals");
        GameSignals.SET_GAMEPLAY_INPUT_STATE.AddListener(SetGameplayInputState);
        GameSignals.SET_GAMEPLAY_INPUT_STATE_OF_LOCAL_PLAYERS.AddListener(SetGameplayInputStateForLocalPlayers);
        GameSignals.SET_MOVEMENT_STATE.AddListener(SetMovementInputState);
        UISignals.INPUT_FIELD_SELECTED.AddListener(OnInputFieldSelected);
        InputSignals.ENABLE_INPUT_ACTION_MAP.AddListener(OnEnableInputActionMap);
        InputSignals.DISABLE_INPUT_ACTION_MAP.AddListener(OnDisableInputActionMap);
        GameSignals.SET_RADIAL_MENU_INPUT_STATE_OF_LOCAL_PLAYERS.AddListener(SetRadialMenuInputStateForLocalPlayers);
    }
    private void UnsubscribeToSignals() {
        GameSignals.SET_GAMEPLAY_INPUT_STATE.RemoveListener(SetGameplayInputState);
        GameSignals.SET_GAMEPLAY_INPUT_STATE_OF_LOCAL_PLAYERS.RemoveListener(SetGameplayInputStateForLocalPlayers);
        GameSignals.SET_MOVEMENT_STATE.RemoveListener(SetMovementInputState);
        UISignals.INPUT_FIELD_SELECTED.RemoveListener(OnInputFieldSelected);
        InputSignals.ENABLE_INPUT_ACTION_MAP.RemoveListener(OnEnableInputActionMap);
        InputSignals.DISABLE_INPUT_ACTION_MAP.RemoveListener(OnDisableInputActionMap);
        GameSignals.SET_RADIAL_MENU_INPUT_STATE_OF_LOCAL_PLAYERS.RemoveListener(SetRadialMenuInputStateForLocalPlayers);
    }
    private void OnInputFieldSelected(MaccimaInputField p_inputField, bool p_isSelected) {
        if (p_inputField.affectsGameplayInputMapState) {
            //disable gameplay input while typing in an input field
            //This is to prevent the player from walking/interacting while they are actively typing.
            SetGameplayInputState(!p_isSelected);    
        }
    }
    private void OnEnableInputActionMap(string p_strActionMapName) {
        EnableInputActionMap(p_strActionMapName);
    }
    private void OnDisableInputActionMap(string p_strActionMapName) {
        DisableInputActionMap(p_strActionMapName);
    }
    private void SetRadialMenuInputStateForLocalPlayers(bool p_state) {
        if (QuantumRunner.Default?.Game != null && QuantumRunner.Default.Game.PlayerIsLocal(_playerRef)) {
            SetRadialMenuInputState(p_state);
        }
    }
    #endregion

    #region Events
    private void SubscribeToEvents() {
        QuantumEvent.Subscribe<EventSetCurrentWeaponEvent>(this, OnSetCurrentWeaponEvent);
        QuantumEvent.Subscribe<EventOnSetCurrentJobStatusEvent>(this, OnSetCurrentJobStatusEvent);
    }
    private void UnsubscribeFromEvents() {
        QuantumEvent.UnsubscribeListener<EventSetCurrentWeaponEvent>(this);
        QuantumEvent.UnsubscribeListener<EventOnSetCurrentJobStatusEvent>(this);
    }
    private void OnSetCurrentWeaponEvent(EventSetCurrentWeaponEvent p_callback) {
        if (p_callback.etyAgent == _entityRef) {
            SetHasWeapon(p_callback.aguidWeapon != default);
        }
    }
    private void OnSetCurrentJobStatusEvent(EventOnSetCurrentJobStatusEvent p_callback) {
        if (p_callback.etyAgent == _entityRef) {
            OnSetCurrentJobStatus(p_callback.jobStatus);
        }
    }
    #endregion

    #region Reconnection
    public unsafe void OnReconnect(Frame p_frame) {
        if (p_frame != null) {
            AgentWeaponComponent* cmpAgentWeapon = p_frame.Unsafe.GetPointer<AgentWeaponComponent>(_entityRef);
            SetHasWeapon(cmpAgentWeapon->aguidCurrentWeapon != default);

            AgentComponent* cmpAgent = p_frame.Unsafe.GetPointer<AgentComponent>(_entityRef);
            OnSetCurrentJobStatus(cmpAgent->currentJobStatus);
        }
    }
    #endregion
}

}

Then this is the name of the bone:

Is this working correctly in the Spine Editor? could you show a screenshot of it in the editor?

Side note I'm having a hard time inderstanding what I have to look at in he screenshots, it would greatly help to focus on those items, or highlight them better.
Thank you

Yes, everything works in the Spine editor, but the issue is that the gun is not actually part of the player's animation. The gun animation is separate from the player's animation.

This is all the animation of the player without the aim animation:

This part consists of 8 items for the player to interact with. However, when the player picks up the gun, it shows the crosshair, and I want the player's arm to follow the crosshair when holding the gun. I'm not sure about the correct code for that:

When I update the code in this part the players arm detaches from the body:
public void Update()
{
if (blnIsHoldingItem)
{
if (
sklamPlayerController == null)
_sklamPlayerController = GetComponent<PlayerController>();

            bone.SetPositionSkeletonSpace(_sklamPlayerController.GetLastAimPosition());
        }
    }

@mrhoody213 While your initial few postings contained far too much code, which makes it impossible to help based on it, your last posting is much more helpful.

I would guess that you are setting the location of the arm bone to the aim-target position, while you should be setting the location of the IK target bone to the target position. The location of the arm bone should be set to the shoulder bone position of your main skeleton. I can't tell for sure without knowing your skeleton bone hierarchies however.

7 дней спустя

I apologize for the second post I made @Harald the issue for the animation is fixed I figured it out. Thank you. I will post another one if it's okay? I have another problem because this game is multiplayer and I don't know why other player doesn't see me moving my arm? But in my pov I see that my arm is rotating.