Anyone working host migrating Photon Fusion advance asteroids in Unity 2022.2.1f1?
Hello!
I'm trying to do running Photon's official Fusion Unity sample game called Advance asteroids.
Everything working on Unity 2022.2.1f1 and build too.
but I was running host on "build file (like an exe file)", and running client version on "editor".
and I did quit host, editor(client) show many error log in each frame.
I think, the reason was GameStateController is not restored(spawn). also releasing log says "isSceneObject: true".
am I need to remove GameStateController GameObject in scene and try to spawning GameStateController? or did testing wrong or need to fix configurations?
Thank you.
Best Answer
-
I've been through the same situation as you, and at I think a little code modification has made it work.
I hope my experience is helpful.
That's the first problem.
GameStateController will not be recreated.
In the process of Host Migration, runner.GetResumeSnapshotNetworkObjects()
The deleted GameState Controller is not loaded.
I don't know exactly why, but it seems that only objects created by Runner.Spawn() are imported.
My solution.
AsteroidsGame.cs
[SerializeField] private GameStateController _gameStateController;
public void OnSceneLoadDone(NetworkRunner runner)
{
runner.Spawn(_gameStateController, Vector3.zero, Quaternion.identity, PlayerRef.None);
}
This is the second problem number two.
Bullets have not been generated, but there are times when an update is attempted.
My solution.
SimpleObjectCollection.cs
public void SimpleFixedUpdateNetwork(NetworkRunner runner, NetworkBehaviour owner)
{
for (int i = 0; i < _states.Length; i++)
{
T state = _states[i];
if (state.IsAlive && null != _gameObjects[i])
{
state.SimpleFixedUpdateNetwork(runner, owner.Object, _gameObjects[i]);
_states[i] = state;
}
}
}
Here's the third problem.
The Spaceship Controller has not found the _gameStateCtrl since migration.
I didn't know the exact reason, but I found the moment when I lost the _gameStateCtrl and put it back in.
My solution.
SpaceshipController.cs
public override void Migrated()
{
base.Migrated();
_gameStateCtrl = GameStateController.FindInstance(Runner);
Runner.AddCallbacks(this);
GameStateCtrl.UpdatePlayer(Object.InputAuthority, this);
}
public override void Despawned(NetworkRunner runner, bool hasState)
{
_bullets.Clear();
_gameStateCtrl = GameStateController.FindInstance(Runner);
_gameStateCtrl .UpdatePlayer(Object.InputAuthority, null);
}
Here's the fourth problem.
There has been a phenomenon in which the score data could not be imported since the migration.
My solution.
MigrationManager.cs
var newNO = runner.Spawn(resumeNO, p,q, PlayerRef.None, (networkRunner, o) =>
{
o.CopyStateFrom(resumeNO);
if(o.TryGetComponent<SpaceshipController>(out var spaceshipController))
{
spaceshipController.CopyStateFrom(resumeNO.GetComponent<SpaceshipController>());
}
newMigrator = o.GetComponent<MigrationBehaviour>();
newMigrator.IsPendingMigration = true;
newMigrator.IsMigrated = true;
});
1
Answers
-
I did 2020.3.35f1, It's not working too.
0 -
I've been through the same situation as you, and at I think a little code modification has made it work.
I hope my experience is helpful.
That's the first problem.
GameStateController will not be recreated.
In the process of Host Migration, runner.GetResumeSnapshotNetworkObjects()
The deleted GameState Controller is not loaded.
I don't know exactly why, but it seems that only objects created by Runner.Spawn() are imported.
My solution.
AsteroidsGame.cs
[SerializeField] private GameStateController _gameStateController;
public void OnSceneLoadDone(NetworkRunner runner)
{
runner.Spawn(_gameStateController, Vector3.zero, Quaternion.identity, PlayerRef.None);
}
This is the second problem number two.
Bullets have not been generated, but there are times when an update is attempted.
My solution.
SimpleObjectCollection.cs
public void SimpleFixedUpdateNetwork(NetworkRunner runner, NetworkBehaviour owner)
{
for (int i = 0; i < _states.Length; i++)
{
T state = _states[i];
if (state.IsAlive && null != _gameObjects[i])
{
state.SimpleFixedUpdateNetwork(runner, owner.Object, _gameObjects[i]);
_states[i] = state;
}
}
}
Here's the third problem.
The Spaceship Controller has not found the _gameStateCtrl since migration.
I didn't know the exact reason, but I found the moment when I lost the _gameStateCtrl and put it back in.
My solution.
SpaceshipController.cs
public override void Migrated()
{
base.Migrated();
_gameStateCtrl = GameStateController.FindInstance(Runner);
Runner.AddCallbacks(this);
GameStateCtrl.UpdatePlayer(Object.InputAuthority, this);
}
public override void Despawned(NetworkRunner runner, bool hasState)
{
_bullets.Clear();
_gameStateCtrl = GameStateController.FindInstance(Runner);
_gameStateCtrl .UpdatePlayer(Object.InputAuthority, null);
}
Here's the fourth problem.
There has been a phenomenon in which the score data could not be imported since the migration.
My solution.
MigrationManager.cs
var newNO = runner.Spawn(resumeNO, p,q, PlayerRef.None, (networkRunner, o) =>
{
o.CopyStateFrom(resumeNO);
if(o.TryGetComponent<SpaceshipController>(out var spaceshipController))
{
spaceshipController.CopyStateFrom(resumeNO.GetComponent<SpaceshipController>());
}
newMigrator = o.GetComponent<MigrationBehaviour>();
newMigrator.IsPendingMigration = true;
newMigrator.IsMigrated = true;
});
1 -
Wow! thank you so much!
0