Retrieve info from Data Classes

NodeCanvas Forums Custom Nodes & Tasks Retrieve info from Data Classes

This topic contains 4 replies, has 2 voices, and was last updated by  Gavalakis 2 weeks, 1 day ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #12561

    scorernb
    Participant

    Is there an example or snippet how to retrieve data in a condition or action from nested data classes?
    let’s say

     public class myRoom {
    public bool hasChair;
    public List<Book> books;
    public Dictionary<string, string> tables
    }
    
    public class Book {
    public string name;
    public string title;
    }
    

    And how to create a node canvas drawer to see the information in the object editor?

    All suggestion are appreciated.

    #12565

    scorernb
    Participant

    First of all, sorry it was the wrong Section…
    problem solved for the class, it should be initialised before use.
    I am a Newbie…

    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;
    using ParadoxNotion.Design;
    
    public class BookDrawer : ObjectDrawer<Book> {
    
    	public override Book OnGUI(GUIContent content, Book instance) {
    		if (instance == null) {
    		    instance = new Book("", "");
    		}
    		GUILayout.BeginVertical("box");
    		instance.name = EditorGUILayout.TextField ("Name", instance.name);
    		instance.title = EditorGUILayout.TextField ("Title", instance.title);
    		GUILayout.EndVertical();
    		return instance;
    	}
    }
    
    #12567

    Gavalakis
    Keymaster

    Hey,

    No problem about the wrong section!
    I am glad you’ve solved the issue with the drawer. Indeed a class should first be initialized so that is not null and the way you are doing it is just fine as well. 🙂

    Regarding your first question about retrieving data in an action/condition Task, considering you are still facing trouble with this, can you please clarify what you mean? I am not sure I correctly understand what you want to do.

    Thanks!

    #12575

    scorernb
    Participant

    Hey,

    The problem was that i want to see in the object editor (blackboard) / task – condition window the data of custom classes. If there is no default initialiser but only custom initialisers the task / condition window freezes and the error count is more then 1000 in a few seconds. The solution for the problem is that i added in all my data-classes a default initialiser. Then the object editor (blackboard) and task window are always displaying the correct information without any custom drawers.

    
    public class myRoom {
    public bool hasChair;
    public List<Book> books;
    public Dictionary<string, string> tables
    
      // for correct display of data in object editor (blackboard) / task window / condition window
       public myRoom() {
         this.hasChair = true;
         this.books = new List<Book>();
         this.tables = new Dictionary<string, string>();
       }
       
       // for use in other methods
       public myRoom(bool _hasChair) {
         this.hasChair = _hasChair;
         this.books = new List<Book>();
         this.tables = new Dictionary<string, string>();
       }
    }
     
    public class Book {
       public string name;
       public string title;
       
       // for correct display of data in object editor (blackboard) / task window / condition window
       public Book() {
          this.name = "";
          this.title = "";
       }
    
       // for use in other methods
       public Book(string _name, string _title ) {
          this.name = _name;
          this.title = _title;
       }
    }
    
    

    What is the purpose of using the custom data / actions and so on …
    Make a FSM that acts on data that is stored in the classes (GlobalBlackBoard), example:
    Condition: hasChair == true
    then
    Action: instantiate a chair.

    #12578

    Gavalakis
    Keymaster

    Thanks for the follow up and the further information! 🙂
    Yes, you can definitely use custom data classes (or structs) in a blackboard and then read that data from within a task.
    If you are facing trouble with this, just let me know.
    Thank you.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.