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;








0















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.


enter image description here


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;












share|improve this question
























  • Possible duplicate of What is a NullReferenceException, and how do I fix it?

    – BugFinder
    Mar 22 at 7:13

















0















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.


enter image description here


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;












share|improve this question
























  • Possible duplicate of What is a NullReferenceException, and how do I fix it?

    – BugFinder
    Mar 22 at 7:13













0












0








0








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.


enter image description here


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;












share|improve this question
















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.


enter image description here


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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현