2
$\begingroup$

I am trying to create an animation nodes project where an empty will be used as an interactive controller for another object. I need to give the empty an initial position away from the origin as the position of the empty determines the size of a mesh.

For the sake of usability and simplicity, I am instancing the empty, rather requiring the user to manually create one and enter it into an object input node.

Here's my problem. I can give the initial position via a transformation output node. However, the empty will then return to those coordinates every time the node tree executes.

My best idea so far is to have some kind of value that indicates whether or not the current execution of the node tree is the first or not. If it is the first, then position the empty at the initial position (e.g. 1,1,0). If it is not the first execution of the node tree, then leave it where it is. However, I do not know if it's even possible to determine that within animation nodes.

I'm illustrating that idea in the image below by having a switch node determine whether to place the instanced empty at a pre-determined position, or allow it to be moved freely by the user. If I could somehow plug in a test for "is this the first execution of the node tree?" into the switch node, then this would work.

Illustration of the fundamental problem

Any ideas, please?

$\endgroup$
1
$\begingroup$

You can test if the object is already in a collection (search from its name). And only if not found, create it and assign the name.

enter image description here

$\endgroup$
8
  • $\begingroup$ Thanks, I like the idea here but it doesn't work. If AN is set to 'Always' execute, then the empty is flickering in and out of existence, and can't even be selected. If we switch off always execute, it still flips back to the initial position whenever the node tree executes. $\endgroup$ – David Gilson Nov 13 '20 at 15:25
  • $\begingroup$ Well, don't have that here... $\endgroup$ – lemon Nov 13 '20 at 15:29
  • $\begingroup$ Have added the blend file, in case of.. $\endgroup$ – lemon Nov 13 '20 at 15:34
  • $\begingroup$ Your file works great for me, but if I try recreating it in my own file, I'm still getting the issue where the node tree executes once, and creates the empty, and on the following execution, the empty is removed, and so on and so on. $\endgroup$ – David Gilson Nov 13 '20 at 23:18
  • $\begingroup$ Can you try opening your file and deleting the empty, and see what happens when the Node Tree tries to re-instance it, please? $\endgroup$ – David Gilson Nov 14 '20 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.