Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sethhalocat · Oct 15, 2017 at 05:40 AM · aienemyloadingsavingreloading

Saving layout and enemy stats with Binary Formatter

So I'm using a binary formatter to save the variables of my script as well as I can. When it comes to the player, everything works perfectly. However I also have an interchanging map aswell as a list of enemies that need to be added aswell. For example, you right click something to activate an animation and delete its collision box. The problem I'm having is, I really need to undo the animation and reset the collision box through a saving and loading system. It's not much of a reverse time rather then a reset to its original variables, including enemy health and location. I would like to be able to list a few enemies, there health, location, and everything else that needs changing, but in order to do that I would need to keep track of the scripts and where they are, but its impossible to save a script prefab, IE:

 [System.Serializable]
 public class EnemyVariables
 {
     public enemyEssentials ESScript;
     public float enemyHealth;
     public float locationX;
     public float locationY;
     public bool isAlive;
 }

will not work. What I currently have is all of that before without actually saving it to my data. IE:

     public void Save ()
     {
         Debug.Log ("Save was started");
         BinaryFormatter bf = new BinaryFormatter ();
         FileStream file = File.Create (Application.persistentDataPath + "/playerInfo.dat");
 
         PlayerData data = new PlayerData ();
 
         //SAVE DATA HERE//
         data.CharacterLocationX = CharacterLocation.x;
         data.CharacterLocationY = CharacterLocation.y;
         data.Health = Health;
         data.Experience = Experience;
         data.Level = Level;
         data.damageLevel = damageLevel;
         data.healthLevel = healthLevel;
         data.delayLevel = delayLevel;
         data.dodgeLevel = dodgeLevel;
         data.ugradeTokens = ugradeTokens;
         data.CUGTokens = CUGTokens;
         data.SpendableCUGTokens = SpendableCUGTokens;
         data.CUGM = CUGM;
         data.tutorialTaskVariables = tutorialTaskVariables;
 
         for (int z = 0; z < enemyVariables.Count; z++) {
             if (enemyVariables [z].ESScript != null) {
                 enemyVariables [z].locationX = enemyVariables [z].ESScript.transform.position.x;
                 enemyVariables [z].locationY = enemyVariables [z].ESScript.transform.position.y;
                 enemyVariables [z].enemyHealth = enemyVariables [z].ESScript.Health;
                 enemyVariables [z].isAlive = enemyVariables [z].ESScript.gameObject.activeSelf;
             }
         }
 
         bf.Serialize (file, data);
         file.Close ();
     }

as you should be able to tell, enemyVariables is not being saved into the saving function otherwise it would work, but it will save temporarily until you exit and re-enter the game. I was curious if there was a work around without having to use exact gameobjects, transforms or scripts so I can get this working. I also would like to know if there is a way to save the map layout for re-enters because I don't currently have that. Of course I could consider it a "Feature" to re-load the specific stats and not the map layout itself but getting things as polished as I can would be even more beautiful...

Thank you so much in advance! - Seth Albertus

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sethhalocat · Oct 15, 2017 at 05:00 PM 0
Share

hello, this is still a pending question <3

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enemy AI Reloading Problem, they reload with queue 0 Answers

Help with Enemy AI 1 Answer

Deal damage on collision 2 Answers

2D sidescroller ranged character shooting problem. 0 Answers

Enemy Spaceship Movement AI Curve Movement Need help Please 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges