- Home /
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
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;
}
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.
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
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
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.
$$anonymous$$yTasks[0].OnTaskStart = null;
$$anonymous$$yTasks[0].OnTaskEnd = null;
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)
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)
If you change it to
public UnityEvent OnTaskStart = null;
public UnityEvent OnTaskEnd = null;
the problem persists?
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
Your answer
Follow this Question
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
mouseposition and clicks in editor sceneview 0 Answers
What is the best way to draw icons in Unity's Hierarchy window? 1 Answer
Editor window doesn't open 2 Answers