How to list objects a script or logic node attached?


#1

Hello,

I’m new to Armory so I’m like a child learning a new environment and have lots of questions :slight_smile:

I’d like to list all the objects a script or logic node attached to them. Is this possible in Blender or Kode Studio?


#2

@ArgosOz, since object references can be fetched during runtime (using Scene.getChild(“objName”) for example) I don’t know any way of getting a list of all objects which is referenced from a trait (script), except keeping track of that manually with an array where you insert and remove references as you go.

The opposite is simple though, object.traits holds an array with all the traits which is associated with that object.


#3

If you are writing the script yourself, it could be done like this:

package arm;

import iron.object.Object;
import iron.Trait;

class MyTrait extends Trait {

	// Static variable shared for all trait instances
	static var users:Array<Object> = [];

	public function new() {
		super();

		notifyOnAdd(function() {
			// Trait was just added to 'object'
			users.push(object);
			// Print to console
			trace(users);
		});
	}
}

Then notifyOnRemove() could be also used to clean up the users array if needed.

To detect if trait is present, doing something like object.getTrait(RigidBody) != null should do.


#4

Thank you all. That’s very helpful.

If I could have a way to see the connection in between traits and objects in Blender, that would be great, quick and easier to follow examples for newbies like me. Right now I have to click through the objects in the Blender’s Outliner to find out the object and the script relations. If I could type the trait name for example, could Blender list the connected objects like this?

Luckily most of the examples have one trait and it’s attached to the camera :slight_smile:


@Lubos, I’d like to thank you very much for all the great work you’ve done. I love the environment very much!


#5

Really cool to hear you love Armory so far!

Showing trait-object relations has become a real issue and I have been thinking a lot on how to fix it. I also wanted to somehow integrate this directly into the Outliner.

I now pushed a commit which is supposed to automatically manage trait groups. Switch to Groups in Outliner and a list of traits should pop up. Each trait has a Trait| prefix so it’s easy to filter. Expanding the group will reveal all objects which have the trait attached. It is then possible to select / hide / remove objects like usual. :slight_smile: Hopefully this improves the situation, will see how it holds up!

(Edit: to auto-update to latest armory http://armory3d.org/manual/dev/gitversion.html may help.)


#6

Just wow! I’m so happy to be a member of Armory community here. Amazing!


#7

Just a remark : it seems that group isn’t available in the outliner with the 2.8 … if true what will be the way to find trait-object relations now ?

(if you discover the blender 2.8 version and don’t understand what’s new in 2.8 and this remark, I suggest that you read this excellent doc info on layers and collection https://code.blender.org/2017/09/view-layers-and-collections/ and this one too https://code.blender.org/2018/05/collections-and-groups/… it’s a magnific Blender evolution that will be of great help for animations :tada:. Thus maybe it’s with using as a first step a special collection for objects equipped with a trait that we can already organize/optimize the exploration/search of traits :slight_smile: waiting for a @Lubos better solution)


#8

@lubos have you planed since some example using the capabilties of the collection and layers within Armory 0.6 / blender 2.8 ?
If I may, personnaly I would be interested to see how to exploit with logic nodes the capabilities of creating instances of a collection, how to hide the original with its derivatives (usage of the View Layers as compositing units, for real-time rendering) and how to limit physics properties to one subset of objects in a scene.


#9

In the git version you should be able to inspect trait users again. Traits are displayed as collections (in the Outliner - Orphan Data view). There are also some collection related logic nodes, but that could still use some more work. :slightly_smiling_face:

traits_groups


#10

@lubos Thanks for answer
a remark : wasn’t it possible/simpler to find traits and logic nodes belonging to a node tree has a hierarchy inside the existing one in the Outliner > Blender File (see thereafter ) ?

image