• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by lTimesl · Dec 30, 2020 at 11:33 AM · unity 5editorunityeditoreditor-scriptingeditorwindow

how to stop reorderable list from passing Event value to the new element

Hey there,

I made a Quest tool which is a node window editor. Every node represents a Quest. The Quest class holds a list of Tasks which I serialised from a ReorderableList

My problem is that I don't know how to reset the event value when new element added to the Reorderable List.

I searched (via google) and I learned how to override the ReorderableList Callbacks. When I overrided the onAdd callback it worked fine, however now I don't find any event to reset the value. I found int string object etc..


To make my problem clearer I have uploaded the image below. As you can see in the image the event value was passed into the new element alt text


Thanks in advance unity community to anyone here that knows how and can help me.

this is the onAddCallback function

  onAddCallback = list =>
                 {
     
                     var index = list.serializedProperty.arraySize;
     
     
                     list.serializedProperty.arraySize++;
                     list.index = index;
     
                     var element = list.serializedProperty.GetArrayElementAtIndex(index);
     
                     //properties of the element in SerializedProperties
                     var task = element.FindPropertyRelative("task");
                     var searchType = element.FindPropertyRelative("searchType");
                     var target = element.FindPropertyRelative("target");
                     var deliverdTaregt = element.FindPropertyRelative("deliverdTaregt");
                     var isCountNeeded = element.FindPropertyRelative("isCountNeeded");
                     var targetLocation = element.FindPropertyRelative("targetLocation");
                     var taskHint = element.FindPropertyRelative("taskHint");
                     var OnTaskStart = element.FindPropertyRelative("OnTaskStart");
                     var OnTaskEnd = element.FindPropertyRelative("OnTaskEnd");
                     var boxColliderSize = element.FindPropertyRelative("colliderSize");
                     var requairdCount = element.FindPropertyRelative("requairdCount");
     
                     // default values
                     task.intValue = (int)Tasks.TaskType.Search;
                     searchType.intValue = (int)Tasks.SearchType.gameObject;
                     target.objectReferenceValue = null;
                     deliverdTaregt.objectReferenceValue = null;
                     isCountNeeded.boolValue = false;
                     targetLocation.vector3Value = Vector3.zero;
                     boxColliderSize.vector3Value = Vector3.zero;
                     taskHint.stringValue = "";
                     requairdCount.intValue = 0;
                     
     
                 }



the task class i create the list of it


 using System.Collections;
 using System.Collections.Generic;
 using UnityEditor;
 using UnityEngine;
 using UnityEngine.Events;
 
 [System.Serializable]
 public class Tasks
 {
     public enum TaskType { Search, Deliver, Counter, Hunt }
     public enum SearchType { gameObject, Area }
     public GameObject target, deliverdTaregt;
     [TextArea]
     public string taskHint;
     public bool isCountNeeded;
 
     public int requairdCount;
 
     public Vector3 targetLocation, colliderSize;
 
     public TaskType task;
     public SearchType searchType;
     public bool isFoldout;
     public UnityEvent OnTaskStart;
     public UnityEvent OnTaskEnd;
 }


rrrr.png (115.8 kB)
Comment

People who like this

0 Show 11
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sacredgeometry · Dec 29, 2020 at 05:35 PM 0
Share

Can you please:


  • Think about the problem you are having.

  • Outline the context other people would need to understand the problem you are having.

  • Edit/ reframe your question in a clear and concise way.

avatar image lTimesl sacredgeometry · Dec 29, 2020 at 11:24 PM 1
Share

I apologize, I do not speak English fluently and I used the translator. I modified the post and I hope the problem is clear.

thanks for your reply

avatar image sacredgeometry lTimesl · Dec 30, 2020 at 04:45 PM 0
Share

Thats instantly much better. Thank you. Let me see if I can edit it to make the english clearer for you once I understand the problem

avatar image sacredgeometry · Dec 30, 2020 at 06:01 PM 0
Share

Im still not 100% sure what you mean. Are you just trying to remove the Event handler for the OnTaskStart and OnTaskEnd Events?

If so what is stopping you from just setting them i.e.

 MyTasks[0].OnTaskStart = null;
 MyTasks[0].OnTaskEnd = null;
avatar image lTimesl sacredgeometry · Dec 31, 2020 at 12:03 AM 0
Share

i did try that b4 to make it null or new it will give you null references exception i think because the instance not yet add (not exist yet)

avatar image lTimesl sacredgeometry · Dec 31, 2020 at 12:08 AM 0
Share

Im still not 100% sure what you mean. Are you just trying to remove the Event handler for the OnTaskStart and OnTaskEnd Events?

yes thats my problem i dont want the events value of previous element to pass to the new Add element i need a way to reset events value like the other fields showed in code sample (onaddcallback)

avatar image MSavioti lTimesl · Dec 31, 2020 at 04:48 AM 0
Share

If you change it to

 public UnityEvent OnTaskStart = null;
 public UnityEvent OnTaskEnd = null;

the problem persists?

Show more comments
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Nyarthotep · Dec 23, 2021 at 12:07 AM

In case anyone comes by this thread, because the drawers are instanced grouped into a single instance, so you need to reference the proper serializedproperty. I the example case, you simply keep a reference to the property's path as the key in a dictionary.

https://answers.unity.com/questions/1479572/how-to-properly-use-reorderablelist-inside-customp.html

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

242 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't remove using Unity Editor, it is necessary for the development of the game. 0 Answers

Create a custom window and set his position on second screen 1 Answer

How to get EditorWindow client rect? 1 Answer

Horizontal Line 12 Answers

reconnect programmatically instantiated prefab 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges