

- #Unity store scene camera in scriptableobject generator#
- #Unity store scene camera in scriptableobject code#
- #Unity store scene camera in scriptableobject series#
Maybe you want to capture a level’s state to save it? Or maybe you need to capture the active-state of gameobjects in a certain situation in your game for debugging?

I can see this easily used for stateful scripts.

In case you haven’t spend the very cost-effective 55$ purchase of the plugin don’t hesitate and just remove the attribute and add this file instead to get the same buttons (TransformsRecorderEditor.cs). The attribute, which is derived from their plugin, does just that - exposes the method as a button. I’m using the excellent, excellent Odin Inspector plugin for editor tools, both at work and at home.
#Unity store scene camera in scriptableobject code#
This bit of the code can be optimized for truly huge game objects, but as a general rule I prefer readability in editor tools I know I won’t use in runtime, and not very often.
#Unity store scene camera in scriptableobject generator#
Fortunately, Transform implements a generator function that will return only the direct children with foreach, as an enumerable. Why do we need the GetDirectChildrenOfTransform method? Because gameobject.GetComponentInChildren will flatten the bottom hierarchy, making it impossible to keep the structure.The recursion step is done on RecordTransformsRecursively.This is a bit overwhelming at first glance. Private List GetDirectChildrenOfTransform(Transform parent)įoreach (Transform directChild in parent) NodeData.ChildrenTransformsData = new List() Var directChildren = GetDirectChildrenOfTransform(parent) Private TransformNode RecordTransformsRecursively(Transform parent)

_transformDataContainer.parentNode = RecordTransformsRecursively(transform) private TransformDataContainer _transformDataContainer Public class TransformRecorder : MonoBehaviour
#Unity store scene camera in scriptableobject series#
Implement some fibonacci series functions! I recommend searching online for tutorials like this or this. If you have no idea what recursion means, you have a deeper knowledge gap that needs to be filled. We’ll traverse the entire transform’s hierarchy recursively, top-down, and persist the properties that interest us into the scriptable object. So we’ve established that our ‘clipboard’ will be a scriptable object. Implementing the ‘record’ of our TransformRecorder meta files, but I will not cover this here). References are not serialized (Unity does serialize references between components and gameobjects through. We have to keep it down to basic serializable types or structs to enjoy storage-persistance. Why can’t I just keep a reference to the Transform? This is because Unity’s Transform is not Serializable. Scriptable Objects - a short introduction And, finally, we’ll implement a load method that’ll read from the scriptable object and place the character just as it was in run mode. Let’s introduce Scriptable Objects (in case you haven’t met them yet) and how they can help us in this, and later implement a simple MonoBehaviour that will allow us to capture the model’s transforms into that scriptable object. I’m not going to individualy move the model to fit this! Especially if I use external models and animations and want to develop rapidly. Since the hierarchy is complex, I can’t use my trusty clipboard and the ‘trick’ I’ve mentioned above. They found him like this in the back alley… Let’s say I want to position the model in a specific scene, ‘frozen’ on this animation’s last frame. Since I can’t use the original model, I’ll use my go-to victim, The Boss model from Mixamo Their FBXs were big, so we wanted to use the same FBXs for different scene with the characters. They were very rich in hierarchy, and had multiple animation sets. Recently I’ve worked on a game with amazing character models. We all know the ol’ trick of accessing the little ‘cog’ above the transform, which allows you to copy a default serialization of a components’ value, and paste it.īut what will you do with a hierarchy that is a bit more… complex? I also solved an emberassing bug present in the previous version,ĮDIT : You can find a sample project containing everything in this post here. EDIT : Hi, I’m from the future, UPM is mature now! You can also use this tool as a package, here.
