[Closed] Object creation / deletion callback timing
I’m trying to create a callback that either adds or removes nodes from an array when they are created / deleted. The problem seems to be that when you start to create the object the callback is called before the object has finished being created (if it even ends up being created at all!)
Is there a simple approach out there to only adjust the array when thee object has definitely been created withou the use of timers?
I can’t find a callback for ‘on node created end’… so I’m using callbacks.addScript #sceneNodeAdded
Any suggestions?
Thanks!
p.
Perhaps this work for you, but it might not be exactly what you are after, as it does add the node when starting creating it (ie. a box), but if you cancel the creation it will remove the node from the array.
(
global AddNode, DeleteNode
local nodes = #()
fn AddNode =
(
append nodes (callbacks.notificationParam())
print (nodes as string)
)
fn DeleteNode =
(
index = finditem nodes (callbacks.notificationParam())
if index != 0 do deleteitem nodes index
print (nodes as string)
)
callbacks.removeScripts id:#ID0X6C61BF500X7E0D486B
callbacks.removeScripts id:#ID0X5A8FD6170X20D8B2CE
callbacks.addScript #sceneNodeAdded "AddNode()" id:#ID0X6C61BF500X7E0D486B
callbacks.addScript #nodePreDelete "DeleteNode()" id:#ID0X5A8FD6170X20D8B2CE
)
Hey Jorge,
Thanks for that! That helped alot.
If anyone else has this issue, I actually ended up using selectedNodesPreDelete callback as it seemed to be a little more robust in this situation.
For the benefit of anyone else dealing with this issue, I came across this thread which uses the isCreatingObject() call to wait for the end of the object creation.
I tend to use a tag on create method, so as to not worry about handling the delete side of things… in it’s simplest form it would work like this…
tag the nodes
fn TagNodeOnCreate =
(
newnode = callbacks.notificationParam();
setAppData newnode 1234 (bit.intAsChar 1);
)
callbacks.addScript #sceneNodeAdded "TagNodeOnCreate()" id:#tag_the_node;
then you can collect the nodes as so…
taggednodes = for obj in objects where bit.charAsInt (getAppData obj 1234) == 1 collect obj