[BUG?] Magic Item: SpawnProjectile does not spawn impacts in some situations for all clients

echtnice

Member
Hi,

i investigated a problem with Magic impacts not beeing spawned in some situation and wanted to share what i found so far. I'm still not 100% sure whats going on but maybe someone of you can help me understand it.

Let's assume that I have two players in a pun session:
---
P1 = player1 (pun master)
P1 = player2
---

When P1 spawn a magic projectile (MP) which he own we have MP(P1)_P1 created by him as he is the pun master. P2 gets notified and creates a corresponding instance MP(P1)_P2 himself. Now we have two Trajectory Objects flying. Either of them can trigger the collision. In case the collision is triggered by MP(P1)_P1 everything is good. But in case MP(P1)_P2 triggers the collision, P1 will not get notified as P2 is not the owner of the projectile (or better he is not the owner of the corresponding MagicItem). P1 will not get notified to trigger impacts but because P2 destroys MP(P1)_P2, MP(P1)_P1 will get destroyed also and might not yet have triggered the collision.

Code:
P1                                                P2
 |                                               |
MagicProjectile                                  |
 |                                               |
SpawnProjectile                                  |
 |                                              |
ObjectPool.Instantiate: MP(P1)_P1                |
|                                                |
NetworkSpawn -------------------------------->  NetworkSpawn MP(P1)_P2
|                                                   |
 |                                        MP(P1)_P2 OnCollision 
 |                                                |
 |                                         MagicItem_PerformImpact 
 |                                                |
 |                                          Impact (local)  <<<<<==== PROBLEM (No NetworkMagicImpact because P2 not owner of MP(P1)_P2)
 |                                                |
 |                                      MagicProjectile.Destroy MP(P1)_P2
 |                                                |
 |                                       NetworkPool.Destroy ---------------> P1
 |                                                |
 |                                          Destroy MP(P1)_P1
MP(P1)_P1 OnCollision
 |
MagicItem_PerformImpact
 |
Impact (local)
 |                                                        P2
NetworkMagicImpact ------------------------------->        |
 |                                                    PerformImpact                    
MagicProjectile.Destroy MP(P1)_P1
 |                                                        P2
NetworkPool.Destroy -------------------------------     |
                                                  Destroy MP(P1)_P2

For now i *fixed* my usecase by ignoring all collisions except on the pun master by changing m_NetworkInfo.IsLocalPlayer to
m_NetworkInfo.IsServer

MagicItem.PerformImpact:773
Code:
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
            // For SpawnProjectiles, it is important to check if m_NetworkInfo.IsServer() to
            // handle collisions only there. otherwise it could happen that impacts are not spawned for one/many of the players
            // depending which MagicProjectile instace triggers the collision.
            if (m_NetworkInfo != null && m_NetworkInfo.IsServer()/*m_NetworkInfo.IsLocalPlayer()*/) {
                m_NetworkCharacter.MagicImpact(this, castID, source, target, hit.point, hit.normal);
            }
#endif

This could be correct for SpawnProjectile cast action because they are also *created* by the master but it is most likely wrong for other cast actions.


After all, everything I sad could be wrong but my change in MagicItem.PerformImpact makes things better for me for now :D

Cheers!
 
Top