public void RestoreSaveData(object dataIn) { if (!enemy) { return; } EnemyData_v1 data = (EnemyData_v1)dataIn; if (data.loadID != LoadID) { return; } DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>(); EnemySenses senses = enemy.GetComponent <EnemySenses>(); EnemyMotor motor = enemy.GetComponent <EnemyMotor>(); EnemyEntity entity = entityBehaviour.Entity as EnemyEntity; // Restore enemy career or class if different if (entity == null || entity.EntityType != data.entityType || entity.CareerIndex != data.careerIndex) { SetupDemoEnemy setupEnemy = enemy.GetComponent <SetupDemoEnemy>(); setupEnemy.ApplyEnemySettings(data.entityType, data.careerIndex, data.mobileGender, data.isHostile, alliedToPlayer: data.alliedToPlayer); setupEnemy.AlignToGround(); if (entity == null) { entity = entityBehaviour.Entity as EnemyEntity; } } // Quiesce entity during state restore entity.Quiesce = true; // Restore enemy data entityBehaviour.gameObject.name = data.gameObjectName; enemy.transform.rotation = data.currentRotation; entity.QuestFoeSpellQueueIndex = data.questFoeSpellQueueIndex; entity.QuestFoeItemQueueIndex = data.questFoeItemQueueIndex; entity.WabbajackActive = data.wabbajackActive; entity.Items.DeserializeItems(data.items); entity.ItemEquipTable.DeserializeEquipTable(data.equipTable, entity.Items); entity.MaxHealth = data.startingHealth; entity.SetHealth(data.currentHealth, true); entity.SetFatigue(data.currentFatigue, true); entity.SetMagicka(data.currentMagicka, true); int team = data.team; if (team > 0) // Added 1 to made backwards compatible. 0 = no team saved { entity.Team = (MobileTeams)(team - 1); } motor.IsHostile = data.isHostile; senses.HasEncounteredPlayer = data.hasEncounteredPlayer; // Restore enemy position and migrate to floating y support for exteriors // Interiors seem to be working fine at this stage with any additional support // Dungeons are not involved with floating y and don't need any changes WorldContext enemyContext = GetEnemyWorldContext(enemy); if (enemyContext == WorldContext.Exterior) { RestoreExteriorPositionHandler(enemy, data, enemyContext); } else { // Everything else enemy.transform.position = data.currentPosition; } // Disable dead enemies if (data.isDead) { entityBehaviour.gameObject.SetActive(false); } // Restore quest resource link enemy.QuestSpawn = data.questSpawn; if (enemy.QuestSpawn) { // Add QuestResourceBehaviour to GameObject QuestResourceBehaviour questResourceBehaviour = entityBehaviour.gameObject.AddComponent <QuestResourceBehaviour>(); questResourceBehaviour.RestoreSaveData(data.questResource); // Destroy QuestResourceBehaviour if no actual quest properties are restored from save if (questResourceBehaviour.QuestUID == 0 || questResourceBehaviour.TargetSymbol == null) { enemy.QuestSpawn = false; Destroy(questResourceBehaviour); } } // Restore instanced effect bundles GetComponent <EntityEffectManager>().RestoreInstancedBundleSaveData(data.instancedEffectBundles); // Resume entity entity.Quiesce = false; }