#CSP / Predicted Spawn / NetworkCollider2D

7 messages · Page 1 of 1 (latest)

upbeat locust
#

Basically, these functions are called from my Player's [Replicate] method :

        public override void LogicUpdate(PlayerRunInputs md, ReplicateState state)
        {
            base.LogicUpdate(md);
            if (state == ReplicateState.CurrentCreated)
                FireProjectile(md.AimDirectionInput, state);
        }

        public void FireProjectile(Vector2 aimDirection, ReplicateState state)
        {
            Vector2 force = aimDirection * pC.playerMovementConfig.fireForce;
            Vector3 aimDirection = force.normalized;
            float spawnDistance = 1.0f; // Distance from the player's center to spawn the projectile
            Vector3 spawnOffset = aimDirection * spawnDistance;
            Vector3 spawnPosition = transform.position + spawnOffset;
            float angle = Mathf.Atan2(force.y, force.x) * Mathf.Rad2Deg;
            Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            NetworkObject nob =
                InstanceFinder.NetworkManager.GetPooledInstantiated(_projectilePrefab, spawnPosition, rotation, true);
            if (!nob)
            {
                Debug.LogError("Projectile prefab is not cached.");
                return;
            }
            BasicRigidbodySync brs = nob.GetComponent<BasicRigidbodySync>();
            if (!brs)
            {
                Debug.LogError("Projectile prefab does not have a BasicRigidbodySync component.");
                return;
            }
            //Spawning the CSP projectile
            InstanceFinder.NetworkManager.ServerManager.Spawn(nob, Owner);
            brs.force = force;
        }
#

@lucid yarrow if you could provide more details about predicted spawning please and my related questions🙏

upbeat locust
#

New error :

FishNet.Object.NetworkBehaviour.<Replicate_NonAuthoritative>g__ReplicateData|91_0[T] (T data, FishNet.Object.ReplicateState state, FishNet.Object.NetworkBehaviour+<>c__DisplayClass91_0`1[T]& ) (at Assets/FishNet/Runtime/Object/NetworkBehaviour.Prediction.cs:729)
FishNet.Object.NetworkBehaviour.Replicate_NonAuthoritative[T] (FishNet.Object.Prediction.Delegating.ReplicateUserLogicDelegate`1[T] del, GameKit.Dependencies.Utilities.BasicQueue`1[T] replicatesQueue, System.Collections.Generic.List`1[T] replicatesHistory, FishNet.Transporting.Channel channel) (at Assets/FishNet/Runtime/Object/NetworkBehaviour.Prediction.cs:668)
Networking.PlayerNetworkHandler.RunInputs (Networking.PlayerMoveReplicateData md, FishNet.Object.ReplicateState state, FishNet.Transporting.Channel channel) <0x444b276c0 + 0x0006f> in <e829dc13d9ab43f1ac03b1dc62690144>:0
Networking.PlayerNetworkHandler.TimeManager_OnTick () (at Assets/Scripts/Networking/PlayerNetworkHandler.cs:78)
FishNet.Managing.Timing.TimeManager.IncreaseTick () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:681)
FishNet.Managing.Timing.TimeManager.<TickUpdate>g__MethodLogic|100_0 () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:346)
FishNet.Managing.Timing.TimeManager.TickUpdate () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:336)
FishNet.Transporting.NetworkReaderLoop.Update () (at Assets/FishNet/Runtime/Transporting/NetworkReaderLoop.cs:28)
lucid yarrow
#

There shouldn't be any NRE errors on the FN side. Is something in your replicate null?

upbeat locust
# lucid yarrow There shouldn't be any NRE errors on the FN side. Is something in your replicate...

This happens when a Client Only spawns a CSP Projectile, using :

 public void Fire(Vector2 force)
        {
            Vector3 aimDirection = force.normalized;
            float spawnDistance = 1.0f; // Distance from the player's center to spawn the projectile
            Vector3 spawnOffset = aimDirection * spawnDistance;
            Vector3 spawnPosition = transform.position + spawnOffset;
            float angle = Mathf.Atan2(force.y, force.x) * Mathf.Rad2Deg;
            Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            if (!InstanceFinder.NetworkManager)
            {
                Debug.LogError("NetworkManager is null.");
                return;
            }
            NetworkObject nob =
                InstanceFinder.NetworkManager.GetPooledInstantiated(_projectilePrefab, spawnPosition, rotation, false);
            if (!nob)
            {
                Debug.LogError("Projectile prefab is not cached.");
                return;
            }
            BasicRigidbodySync brs = nob.GetComponent<BasicRigidbodySync>();
            if (!brs)
            {
                Debug.LogError("Projectile prefab does not have a BasicRigidbodySync component.");
                return;
            }
            brs.SetOwner(gameObject.GetComponent<NetworkObject>());
            InstanceFinder.ServerManager.Spawn(nob, Owner);
            brs.force = force;
        }

this seems like an error from FN Side, I've followed this guide for my CSP projectile : https://fish-networking.gitbook.io/docs/manual/guides/prediction/version-2/creating-code/non-controlled-object

A very simple script for keeping non-controlled objects in synchronization with the prediction system.

#

@lucid yarrow , the only thing that differs from the guide is that my CSP uncontrolled object is a rigidbody2D projectile.
so my [Replicate] is not empty, as shown in the guide, since I want to apply some physics :

[Replicate]
        private void Move(ReplicateData rd, ReplicateState state = ReplicateState.Invalid,
            Channel channel = Channel.Unreliable)
        {
            if (!isLocallyAlive)
            {
                if (graphicalObject != null)
                {
                    graphicalObject.SetActive(false);
                }
                return;
            }

            // TODO: Move this to the ScriptableObject
            Vector2 desiredVelocity = force.normalized * 10f;

            ProjectilePredictionRigidbody2D.Velocity(desiredVelocity);
            ProjectilePredictionRigidbody2D.Simulate();
        }

maybe that's the issue ?

lucid yarrow