Loading script values

Hey there guys, in a bind…

I have created my own saving/loading system, which works exactly as I’d like.
But there’s one last piece to the puzzle I’m stumped with.

I can save the component values, but it hadn’t hit me yet but I realized as soon as I started making the “Loading” script that I couldn’t do Component c = <TypeFoundInLoad>().SomeVariable.

I can FIND the type during load, I just don’t know how to access the variable, because Component isn’t exactly Health h = GetComponent<Health>().health = 100. (Hence I need to figure out how to get the part at the end ().health = “ValueFoundInLoad”.)

So here’s the break down of what I am doing.
I am saving transform position and rotation, and all the components and their values to a custom made saving file.

It looks pretty much like this,

pos.x = 100
pos.y = 100
pos.z = 100
rot.x = 100
rot.y = 100
rot.z = 100
(c) // Reader reads this line and knows the next following is components

Health // Gets the name of the Component (which in this case is HEALTH.
true // this is to determine if it's enabled or not (which works).
100 // 100 Health

(c/) // Means we are done with components.

The //Comments are just so you know what things are, it’s not saved in the save.
What I need to figure out is the last thing inside the save file.



I need to sync that to the proper variable, but I’m not sure how that’s doable. I know it is, just need a bit of guidance.

Figured it out finally guys.

Here’s the code.

						// We get the variable name with TempString
						// then we set the value using variableValue.
						FieldInfo[] info = c.GetType ().GetFields ();
						foreach (FieldInfo inf in info) {
							FieldInfo name = c.GetType ().GetField (tempString);
							int intVal = Convert.ToInt32(variableValue);
							if (name != null) {
								name.SetValue (

Hi, if I understood well you can’t get the variable of a component, the health of the player. You musn’ t use Health health = GetComponent<Health>().health, you must use int health = GetComponent<Health>().health. You can’t use Health health = GetComponent<Health>().health because you can’t say that a class is an int.