Get and Set System.Object value using Unity SerializedPropertiesWhat is a NullReferenceException, and how do I fix it?How do you give a C# Auto-Property a default value?Overriding fields or properties in subclassesHow do I get a consistent byte representation of strings in C# without manually specifying an encoding?How to get the list of properties of a class?Get int value from enum in C#How to loop through all enum values in C#?Sorting JavaScript Object by property valueUsing c#, How can I take benefit of using nullable valuetypes when I have a variable of object type?What is the get; set; syntax in C#?Check if a value is an object in JavaScript
Prime joint compound before latex paint?
extract characters between two commas?
What does "enim et" mean?
How would photo IDs work for shapeshifters?
Does the average primeness of natural numbers tend to zero?
Is Social Media Science Fiction?
How to make payment on the internet without leaving a money trail?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?
Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?
Could a US political party gain complete control over the government by removing checks & balances?
How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)
Extreme, but not acceptable situation and I can't start the work tomorrow morning
Is there a familial term for apples and pears?
"listening to me about as much as you're listening to this pole here"
How can I fix this gap between bookcases I made?
Are objects structures and/or vice versa?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Are white and non-white police officers equally likely to kill black suspects?
Typesetting a double Over Dot on top of a symbol
Is there a way to make member function NOT callable from constructor?
What do the Banks children have against barley water?
Domain expired, GoDaddy holds it and is asking more money
Shall I use personal or official e-mail account when registering to external websites for work purpose?
Get and Set System.Object value using Unity SerializedProperties
What is a NullReferenceException, and how do I fix it?How do you give a C# Auto-Property a default value?Overriding fields or properties in subclassesHow do I get a consistent byte representation of strings in C# without manually specifying an encoding?How to get the list of properties of a class?Get int value from enum in C#How to loop through all enum values in C#?Sorting JavaScript Object by property valueUsing c#, How can I take benefit of using nullable valuetypes when I have a variable of object type?What is the get; set; syntax in C#?Check if a value is an object in JavaScript
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to be able to specify the type with an enum and assign the value to the object variable, but I keep getting 'NullReferenceException ..' error message.
I have this simple class:
[System.Serializable()]
public class ObjectValue
public enum ValueType Null, Integar, Float, String, Boolean
[SerializeField, HideInInspector] private ValueType type = ValueType.Null;
public object value = null;
And by the help of a property drawer script I want to be able to view this class on the Inspector and edit the value depending on the chosen type:
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ObjectValue))]
public class ObjectValue_Drawer : PropertyDrawer
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
return base.GetPropertyHeight(property, label) + 17;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
GUI.Box(position, GUIContent.none);
var typeEnum = property.FindPropertyRelative("type");
position.height = 17;
EditorGUI.PropertyField(position, typeEnum);
position.y += 17;
var value = property.FindPropertyRelative("value");
switch (typeEnum.enumValueIndex)
case (int)ObjectValue.ValueType.Null:
GUI.Label(position, "Null Value Type");
break;
case (int)ObjectValue.ValueType.Integar:
value.intValue = EditorGUI.IntField(position, "Value", value.intValue);
break;
case (int)ObjectValue.ValueType.Float:
value.floatValue = EditorGUI.FloatField(position, "Value", value.floatValue);
break;
case (int)ObjectValue.ValueType.String:
value.stringValue = EditorGUI.TextField(position, "Value", value.stringValue);
break;
case (int)ObjectValue.ValueType.Boolean:
value.boolValue = EditorGUI.Toggle(position, "Value", value.boolValue);
break;
c# object unity3d types properties
add a comment |
I want to be able to specify the type with an enum and assign the value to the object variable, but I keep getting 'NullReferenceException ..' error message.
I have this simple class:
[System.Serializable()]
public class ObjectValue
public enum ValueType Null, Integar, Float, String, Boolean
[SerializeField, HideInInspector] private ValueType type = ValueType.Null;
public object value = null;
And by the help of a property drawer script I want to be able to view this class on the Inspector and edit the value depending on the chosen type:
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ObjectValue))]
public class ObjectValue_Drawer : PropertyDrawer
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
return base.GetPropertyHeight(property, label) + 17;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
GUI.Box(position, GUIContent.none);
var typeEnum = property.FindPropertyRelative("type");
position.height = 17;
EditorGUI.PropertyField(position, typeEnum);
position.y += 17;
var value = property.FindPropertyRelative("value");
switch (typeEnum.enumValueIndex)
case (int)ObjectValue.ValueType.Null:
GUI.Label(position, "Null Value Type");
break;
case (int)ObjectValue.ValueType.Integar:
value.intValue = EditorGUI.IntField(position, "Value", value.intValue);
break;
case (int)ObjectValue.ValueType.Float:
value.floatValue = EditorGUI.FloatField(position, "Value", value.floatValue);
break;
case (int)ObjectValue.ValueType.String:
value.stringValue = EditorGUI.TextField(position, "Value", value.stringValue);
break;
case (int)ObjectValue.ValueType.Boolean:
value.boolValue = EditorGUI.Toggle(position, "Value", value.boolValue);
break;
c# object unity3d types properties
Possible duplicate of What is a NullReferenceException, and how do I fix it?
– BugFinder
Mar 22 at 7:13
add a comment |
I want to be able to specify the type with an enum and assign the value to the object variable, but I keep getting 'NullReferenceException ..' error message.
I have this simple class:
[System.Serializable()]
public class ObjectValue
public enum ValueType Null, Integar, Float, String, Boolean
[SerializeField, HideInInspector] private ValueType type = ValueType.Null;
public object value = null;
And by the help of a property drawer script I want to be able to view this class on the Inspector and edit the value depending on the chosen type:
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ObjectValue))]
public class ObjectValue_Drawer : PropertyDrawer
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
return base.GetPropertyHeight(property, label) + 17;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
GUI.Box(position, GUIContent.none);
var typeEnum = property.FindPropertyRelative("type");
position.height = 17;
EditorGUI.PropertyField(position, typeEnum);
position.y += 17;
var value = property.FindPropertyRelative("value");
switch (typeEnum.enumValueIndex)
case (int)ObjectValue.ValueType.Null:
GUI.Label(position, "Null Value Type");
break;
case (int)ObjectValue.ValueType.Integar:
value.intValue = EditorGUI.IntField(position, "Value", value.intValue);
break;
case (int)ObjectValue.ValueType.Float:
value.floatValue = EditorGUI.FloatField(position, "Value", value.floatValue);
break;
case (int)ObjectValue.ValueType.String:
value.stringValue = EditorGUI.TextField(position, "Value", value.stringValue);
break;
case (int)ObjectValue.ValueType.Boolean:
value.boolValue = EditorGUI.Toggle(position, "Value", value.boolValue);
break;
c# object unity3d types properties
I want to be able to specify the type with an enum and assign the value to the object variable, but I keep getting 'NullReferenceException ..' error message.
I have this simple class:
[System.Serializable()]
public class ObjectValue
public enum ValueType Null, Integar, Float, String, Boolean
[SerializeField, HideInInspector] private ValueType type = ValueType.Null;
public object value = null;
And by the help of a property drawer script I want to be able to view this class on the Inspector and edit the value depending on the chosen type:
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ObjectValue))]
public class ObjectValue_Drawer : PropertyDrawer
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
return base.GetPropertyHeight(property, label) + 17;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
GUI.Box(position, GUIContent.none);
var typeEnum = property.FindPropertyRelative("type");
position.height = 17;
EditorGUI.PropertyField(position, typeEnum);
position.y += 17;
var value = property.FindPropertyRelative("value");
switch (typeEnum.enumValueIndex)
case (int)ObjectValue.ValueType.Null:
GUI.Label(position, "Null Value Type");
break;
case (int)ObjectValue.ValueType.Integar:
value.intValue = EditorGUI.IntField(position, "Value", value.intValue);
break;
case (int)ObjectValue.ValueType.Float:
value.floatValue = EditorGUI.FloatField(position, "Value", value.floatValue);
break;
case (int)ObjectValue.ValueType.String:
value.stringValue = EditorGUI.TextField(position, "Value", value.stringValue);
break;
case (int)ObjectValue.ValueType.Boolean:
value.boolValue = EditorGUI.Toggle(position, "Value", value.boolValue);
break;
c# object unity3d types properties
c# object unity3d types properties
edited Mar 22 at 2:05
UnknownUser
asked Mar 22 at 1:37
UnknownUserUnknownUser
427
427
Possible duplicate of What is a NullReferenceException, and how do I fix it?
– BugFinder
Mar 22 at 7:13
add a comment |
Possible duplicate of What is a NullReferenceException, and how do I fix it?
– BugFinder
Mar 22 at 7:13
Possible duplicate of What is a NullReferenceException, and how do I fix it?
– BugFinder
Mar 22 at 7:13
Possible duplicate of What is a NullReferenceException, and how do I fix it?
– BugFinder
Mar 22 at 7:13
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291656%2fget-and-set-system-object-value-using-unity-serializedproperties%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291656%2fget-and-set-system-object-value-using-unity-serializedproperties%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of What is a NullReferenceException, and how do I fix it?
– BugFinder
Mar 22 at 7:13