{"action":"created","issue":{"url":"https://api.github.com/repos/TheSniperFan/unityserializer-ng/issues/22","labels_url":"https://api.github.com/repos/TheSniperFan/unityserializer-ng/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/TheSniperFan/unityserializer-ng/issues/22/comments","events_url":"https://api.github.com/repos/TheSniperFan/unityserializer-ng/issues/22/events","html_url":"https://github.com/TheSniperFan/unityserializer-ng/issues/22","id":97974690,"number":22,"title":"Re-establish links to GameObjects/MonoBehaviours","user":{"login":"Pikl","id":7017102,"avatar_url":"https://avatars.githubusercontent.com/u/7017102?v=3","gravatar_id":"","url":"https://api.github.com/users/Pikl","html_url":"https://github.com/Pikl","followers_url":"https://api.github.com/users/Pikl/followers","following_url":"https://api.github.com/users/Pikl/following{/other_user}","gists_url":"https://api.github.com/users/Pikl/gists{/gist_id}","starred_url":"https://api.github.com/users/Pikl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pikl/subscriptions","organizations_url":"https://api.github.com/users/Pikl/orgs","repos_url":"https://api.github.com/users/Pikl/repos","events_url":"https://api.github.com/users/Pikl/events{/privacy}","received_events_url":"https://api.github.com/users/Pikl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-29T16:26:57Z","updated_at":"2015-07-31T02:17:49Z","closed_at":null,"body":"Hi there dude, first of all, you're awesome.\r\nI found the original serializer recently and was saddened to learn that it doesn't support unity 5 and was just looking into updating it for my project when i stumbled across this wonderful repository. So, thanks!\r\n\r\nAnyway, I tried to test it on my StateObjects - a GameObject-ish class that's built to run state machines. Now, within the classes for the states (behaviour) there is a StateObject reference, so that the states can access the GameObject it's running on. \r\n\r\nThis reference gets removed when loading a saved game and I'm unable to add it back in when the objects are reconstructed (parameterless constructor) because of how I've built my state machine - it allows states to be stacked up to perform sequences of actions and the States can not get their StateObject reference until they get initialised. \r\nThere are several other reasons why I'm unable to get this reference out of nowhere, I'm sure you understand.\r\n\r\nMaking the State class inherit from MonoBehaviour would fix this problem as I could store the States in a child object of the StateObject, and have the States as components, then use something like transform.parent.root to always have a reference to the StateObject. \r\nBut this is not really an option for me as it'd completely change the way my framework & game is structured.\r\n\r\nI'm not quite sure why I'm posting an issue about this, as it seems to be my problem, not yours.\r\nBut any insight you've got would be great - I may be missing something glaringly obvious, as I'm at a loss as to how to proceed and I would really like to use the serializer."},"comment":{"url":"https://api.github.com/repos/TheSniperFan/unityserializer-ng/issues/comments/126543728","html_url":"https://github.com/TheSniperFan/unityserializer-ng/issues/22#issuecomment-126543728","issue_url":"https://api.github.com/repos/TheSniperFan/unityserializer-ng/issues/22","id":126543728,"user":{"login":"Pikl","id":7017102,"avatar_url":"https://avatars.githubusercontent.com/u/7017102?v=3","gravatar_id":"","url":"https://api.github.com/users/Pikl","html_url":"https://github.com/Pikl","followers_url":"https://api.github.com/users/Pikl/followers","following_url":"https://api.github.com/users/Pikl/following{/other_user}","gists_url":"https://api.github.com/users/Pikl/gists{/gist_id}","starred_url":"https://api.github.com/users/Pikl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pikl/subscriptions","organizations_url":"https://api.github.com/users/Pikl/orgs","repos_url":"https://api.github.com/users/Pikl/repos","events_url":"https://api.github.com/users/Pikl/events{/privacy}","received_events_url":"https://api.github.com/users/Pikl/received_events","type":"User","site_admin":false},"created_at":"2015-07-31T02:17:49Z","updated_at":"2015-07-31T02:17:49Z","body":"I had not tried that!\r\n\r\nUnfortunately that doesn't seem to change anything that I can see.\r\nI still get the same NullReferenceException from my objects (player and enemies).\r\nI've tried various different combinations of several annotations, such as [SerializeAll] on the class, [SerializeField], [System.Serializable], and nothing seems to change. \r\nI may be doing this in entirely the wrong place.\r\nI must admit I'm not too familiar with serialization - I should probably fix that.\r\n\r\nI've pasted stripped down versions of my State and StateObject classes, hoping to give you a bit of context.\r\n```C#\r\npublic class State {\r\n\t[SerializeThis]\r\n\tinternal StateObject so;\r\n\tinternal float lifetime, originalLifetime;\r\n\r\n\tpublic State() { }\r\n\r\n\tpublic State(float lifetime) {\r\n\t\tthis.lifetime = lifetime;\r\n\t\toriginalLifetime = lifetime;\r\n\t}\r\n\r\n\t//This is where I 'initialize' the state, when a state switch happens, \r\n\t//i.e. idle state to running state.\r\n\tinternal virtual void Enter(StateObject so) {\r\n\t\tthis.so = so;\r\n\t}\r\n\r\n\tinternal virtual State Update() {\r\n\t\tif(originalLifetime > 0 && lifetime -= Time.deltaTime == 0)\r\n\t\t\tso.RevertToPreviousState();//NullReferenceException for so\r\n\t}\r\n\r\n\t//I do a lot of cloning within my StateSequences/NestedStateSequences.\r\n\t//Could this be causing problems?\r\n\tpublic object Clone() {\r\n\t\treturn new MemberwiseClone();\r\n\t}\r\n}\r\n\r\npublic class StateObject : MonoBehaviour {\r\n    public State CurrentState {\r\n        get {\r\n            return state.Peek().Peek();\r\n        }\r\n    }\r\n    //StateHistory is a class that contains a nested stack of states,\r\n    //States are remembered up to a point - the stack is open,\r\n    //letting the bottom items fall off when capacity is reached.\r\n    StateHistory state;\r\n\r\n    void Update() {\r\n        CurrentState.Update();\r\n    }\r\n}\r\n```"}}