How to define a SerializedObject as Array on Custom Inspector Script? (888637)

Hello everyone, maybe it’s something simple that i can’t find or i don’t know,
I can get int, float or object properties but I cant get the array value of a SerializedProperty in a custom inspector script

I made a script that used by selection of rotated body parts of a 2D character, actually it is completed, I made all built-in values private and I made read-only versions of the same values that used in custom inspector script but I’m just asking because I was wondering is there a method like that? My second question is does public access modifiers cause security vulnerability?

screenshot https://drive.google.com/file/d/1u7Bbtl6HeZ0SEGxknaedW4cckAugcwrc/view?usp=sharing

I will try to explain with a clear and simple example as possible:

 on base.cs:
[SerializeField] GameObject[]  someGameObjects;
[SerializeField ]int anyInt = 0;

on custom inspector editor.cs:
SerializedObject m_GameObjArrayElement;
SerializedObject m_IntVal;
OnEnable()
{
       m_GameObjArrayElement = serializedObject.FindProperty("someGameObjects");
       m_IntVal = serializedObject.FindProperty("anyInt");
}
OnInspectorGUI()
{
          m_IntVal.IntValue = 5;  // I was able to get the int value with the conversion function inside the SerializedProperty class itself, How can I convert array values like that?
     
          main( m_GameObjArrayElement.ArrayValue() );  // i need a command that works like in this field "m_GameObjArrayElement.ArrayValue()", but I couldn't find anything like this..

}

void main(GameObject[] gameObjects)
{
       //some operations
}

Any ideas ? :smiley:

Is this C#? It somehow doesn’t even look like it.

Anyways, I found this thread about the topic, hope it’s the right solution for you.

http://answers.unity.com/answers/1419238/view.html

 SerializedProperty m_Speed;
     public void OnEnable()
     {
         m_Speed = this.serializedObject.FindProperty("speed");
     }
     public override void OnInspectorGUI(){
         serializedObject.Update ();
         for (int x = 0; x < m_Speed.arraySize; x++) {
             SerializedProperty property = m_Speed.GetArrayElementAtIndex (x); // get array element at x
             property.floatValue = Mathf.Max (0,property.floatValue); // Edit this element's value, in this case limit the float's value to a positive value.
         }
         EditorGUILayout.PropertyField(m_Speed,true); // draw property with it's children
         serializedObject.ApplyModifiedProperties ();
     }

(copied from the link)

Hello thanks!, It may not be relevant but I have another question, I’m really stuck with interesting details right now, how can I access a private void in an another script? I guess there is no other way other than “invoke”, “sendMessage” “broadcastmessage” methods…

Out of box you cannot. Placing private on it is part of the contract that says “don’t manipulate this, I might change it in the future.”

Instead, make an API to get at it, for instance a public getter method in the class:

public GetValueILikeToKeepPrivate()
{
  // now in the future you can change however you get this, and nobody outside
  // of here should care, making CIS majors feel all nice and warm and fuzzy.
  return thePrivateValue;
}

Thanks! what i’m trying to do is just this, The delay in updating the bones is due to the delay in the lateupdate of the spriteskin component, as seen in the video

https://www.youtube.com/watch?v=jXhgnm4rDpE

Adding the following lines to the code page solves the problem, but everywhere they say that this sendmessage or invoke is an expensive method, I looked it with profiler, but I don’t know, it doesn’t seem to matter much, generally the CPU usage goes up and down in 6ms with my script or not…

                Transform variationTransform = variations[i].transform;
                for (int x = 0; x < variationTransform.childCount; x++)
                {
                    variationTransform.GetChild(x).GetComponent<SpriteSkin>().Invoke("LateUpdate", 0);
                }

I can add delegates and cache the all the lateupdate commands in all these sprite skins with system reflection, but it seems to me to be an indirect way…

I don’t see the delay you speak of… you mean the flicker? Is that perhaps just not updating before displaying?? Everything in Unity scripting is essentially single-threaded. Perhaps this can give you timing insight:

Here is some timing diagram help:

https://docs.unity3d.com/Manual/ExecutionOrder.html

You did right… you did not listen to the noise on the internet and you reached for the profiler.

If it’s not a problem, it’s not a problem. Go forward. I used SendMessage for pretty much everything in my first Unity game (Rocket Raiders) and I never bothered going back and changing it… because it works fine!!

https://www.youtube.com/watch?v=a_FfvgDd99M

Thanks for the answer, you’re right in your words, when you get too caught up in something, the project doesn’t end. I can explain it like this, without the delay seen in the video. I tried changing the execution order when my methods in late update but it doesn’t work, sprite skin repositioning the bones late as a frame because sprite skin runs with late update. If you type the commands in update instead of late update, such a problem does not occur, the sprite skin fixes bones in next frame,
or if you create an endless loop with a coroutine executing every 0.1 sec just like a kind of fixed update and write all the commands in it because it runs before late update.
I knew about late update but forgot its definition, I thought the late update was something more cheap but now I researched and it was the same as update, so it will be cheaper if I write to update instead of using invoke or sendmessage, it is good to not overlook or forget some details. :smiley:

https://www.youtube.com/watch?v=F9FnctsY2uE