jstree - enabling copy operation between trees disables the move operation inside one tree - drag-and-drop

I have 2 jstrees. TreeSource and TreeDestination. I want only the copy operation to be enabled while moving the nodes between trees. In my TreeDestination I have the below line inside check_callback.
if (more) {
more.origin.settings.dnd.always_copy = true;
}
Now, many of the cases work fine with this. That is, the copy operation takes place between the nodes when dragging them from one tree to another and vice versa. However, now when I move the nodes of tree TreeSource inside the tree itself, they are not moved, but getting copied. Looks like more.origin.settings.dnd.always_copy = true; is affecting both the trees, despite declaring only in the TreeDestination.
How can I resolve this?

Related

Why is "Cast to BP_Ladder" failing all the time?

I am having trouble with my Unreal Engine 4 project. I'm very new to this and i don't really understand what's going on. I have made ladder functionality so the character can climb up the ladder and stand on the Static Mesh that is on top. But when i want to go down the ladder i want to trigger the "Allow Down" function on Actor "BP_Ladder" but the cast is failing everytime. what is causing the casts to fail?
I've looked around and other people with cast failed problems have mostly had the names wrong but my ladder is called "BP_Ladder" and that is what i'm casting to so that leaves me really confused.
My BP_Dude blueprint (this is being called every tick)
My BP_Ladder blueprint (this is what i'm trying to trigger)
The goal for this function is that the collision of the static mesh will turn off and then allow me to move down the ladder like normal.
I'd really appreciate your help with this, its my first couple of days using unreal engine and the Epic Games tutorials i followed didn't show all of the blueprints so everyone was left helpless with half broken blueprints.
Understanding Casts
In its simplest form, if your Actor can be cast to BP_Ladder, then it will return the casted object on the output pin.
Just to ensure you know how a cast works, I have to point out that you can't cast a given type to some unrelated arbitrary type; it has to be "castable" to the cast destination. So if you think that the Actor object returned by your overlap is genuinely a BP_Ladder, or a blueprint class that derives from BP_Ladder, then you should be OK. But that has to be the case; otherwise it will fail every time.
https://docs.unrealengine.com/en-us/Engine/Blueprints/UserGuide/CastNodes
Sorry if I'm being patronising, but if a cast isn't working 9/10 it hasn't been used correctly.
Debugging
OK that out of the way, if you think you are genuinely casting to the correct type and it's still failing, then you'll need to debug your blueprint with the objective of finding what type is being given to the cast node which results in the failure.
Select the cast object in your blueprint.
Press F9 to create a breakpoint; a red circle should appear on the top left of your cast box
Run your game in PIE mode (Combo next to play, New Editor Window (PIE))
Put the game in a scenario where your cast will fire (I presume touch the ladder)
The breakpoint should trigger; your game window will go grey and you'll get a large red arrow pointing down towards your cast box where you placed the breakpoint
Hover over the Object pin on the input side of the cast box. It should show a alt-text containing details of the variable.
Inside the alt-text box, look for Current value; this should show you the current object type that you are about to cast. You need to ensure that this value is what you expect.
https://docs.unrealengine.com/en-US/Engine/Blueprints/UserGuide/Debugging
Example
I've taken a screenshot of a working game; in this you will see:
a Breakpoint (the red circle) is shown on the function node (the box)
the Execution node (red arrow) is Create Rolling Stock
the Current value of the variable is DepotComponent...Depot
Final thoughts
There's a couple of gotchas when using blueprints; one of them in this case could be that you can have two classes with the same name (although they might have different internal "script names" - effectively a fully qualified path). When you debugging an object variable, make sure you match the entire path to the location of your asset in your content folder; this will ensure that you are indeed attempting to cast to the object you think you really are.
Another classic gotcha is "hot reloads". Sometimes the editor needs to reload a module after an on-the-fly build but a class conflict occurs internally; this results in the new version of the class getting a different name (prefixed with HOTRELOADED). Watch out for this; it can cause you to be dealing with two distinct types when casting and you don't even realise. A real sanity-sapper. If in doubt, close and re-open the editor; it fixes it every time.
On Begin Overlap is only triggered when you START an overlap, so if you have some logic that sets your "can climb" to false you will need to move outside of the collider and back into it again for another Begin Overlap event.

UE4 Objects overlap position after collision

I'm new to unreal engine, I'm trying to add large force to an object with a box collider but after it collide with other object (just another instance) the overlap inside each others and become like one object and moving with each others.
Cab anyone explain their behavior and how i should resolve this?
What happens here is that both objects collide with each other continously. To fix that you could try to deactive the OnOverlap()-Event on either the overlapping Object or the colliding object.
In blueprints you can achieve that by setting the Generate Overlap Events-Variable of one of the colliding static meshes of the overlapping objects to false.
In C++ you could simply remove the dynamic event callback for one of the colliding objects like that:
CollidingComponent->OnComponentBeginOverlap.RemoveDynamic(this, &ACollidingActor::OnBeginOverlap);
Where CollidingComponent is the component of your object, which causes the overlap event to trigger.
Like #Alex said, they overlap with each other, over and over. If you didn't know, you can add breakpoints to your blueprint nodes, just like in your code, by right-clicking a node and select Enable Breakpoint (or smth like that). Your game will stop when reaching it and switch to that exact point in your blueprint. You can then hover over that node and see every variables value going in and out of it.
Hope this helps you learing to use the Unreal Engine.

A Grid of Clones

My goal is to build a 5x5 grid of images. In the following code, row, col and rowcol were created as variables local to the sprite, and newcol, newrow and cats are global. (By the way, is it possible to tell which variables are local and which are global? It's easy to forget or make mistakes.)
The result is a 5x1 grid only, as seen here.
I am unclear as to the order of execution of these statements. Does when I start as a clone get called before or after add_cat gets called the second time? My tentative conclusion is that it gets called afterwards, yet the clone's global variables seem to contain their values from beforehand instead.
When I attempted to debug it with ask and say and wait commands, the results varied wildly. Adding such pauses in some places fixed the problem completely, resulting in a 5x5 grid. In other places, they caused a 1x5 grid.
The main question is: How to fix this so that it produces a 5x5 grid?
Explanation
Unfortunately, the execution order in Scratch is a little bizarre. Whenever you edit a script (by adding or removing blocks, editing inputs, or dragging the entire script to a new location in the editor), it gets placed at the bottom of the list (so it runs last).
A good way to test this out is to create a blank project with the following scripts:
When you click the green flag, the sprite will either say "script one" or "script two", depending on which runs first. Try clicking and dragging one of the when green flag clicked blocks. The next time you click the green flag, the sprite will say whichever message corresponds to the script you just dragged.
This crazy order can make execution incredibly unpredictable, especially when using clones.
The solution
The only real solution is to write code that has a definite execution order built-in (rather than relying on the whims of the editor). For simpler scripts, this generally means utilizing the broadcast and wait block to run particular events in the necessary order.
For your specific project, I see two main solutions:
Procedural Solution
This is the most straightforward script, and it's probably what I would choose to go with:
(row and col are both sprite-only variables)
Because clones inherit all sprite-only variable values when they are created, each clone will be guaranteed to have the correct row and col when it is created.
Recursive Solution
This solution is a bit harder to understand than the first, so I would probably avoid it unless you're just looking for the novelty:

How to remove undo from history (RevertAllInCurrentGroup?)

I'm trying to use RevertAllInCurrentGroup to undo the last operation but it doesn't seem to work. Actually what I really want to do is just remove the undo from the history; I don't care whether the undo is applied or not.
In some init code I have:
// 'component' is a MonoBehaviour-derived class. Here I create the default editor for the component
m_editor = Editor.CreateEditor(component);
And then in OnGUI in my EditorWindow:
m_editor.OnInspectorGUI();
// ..'hasChanged' is set to true if the user changed some property
if (hasChanged)
{
// ..do some stuff using the new values on the object, which includes sending a message to a server
Undo.RevertAllInCurrentGroup();
}
When I call RevertAllInCurrentGroup I get InvalidOperationException: Operation is not valid due to the current state of the object in some Stack object in GUILayoutUtility.EndLayoutGroup. I figured maybe I shouldn't be doing the revert in OnGUI, so I changed it to set a flag and do the revert in Update but that doesn't make any difference (except I obviously no longer get the exception).
Does anyone know how to use this function, or if there is some other way that I could undo the last operation that was applied by the Editor instance? I've tried using Undo.RegisterCompleteObjectUndo and Undo.ClearUndo but they don't seem to do anything either (the undo operation still appears in the undo stack).
For clarification, I'm dynamically creating GameObjects with components in the editor based on messages I receive from a server (which is a running Unity game, which could be inside or outside the editor - this is a live update system). Then I allow editing of those components, and send the changed components back to the server. I'm rendering my own inspector UI and I wanted to use the built-in Editor instances for components (e.g. so the built-in CameraEditor will be used if there is a Camera component).
The only problem is that using the built-in editors causes undo operations to be added to the stack, but I really don't care about these undo operations because the GameObject they apply to is just a temporary placeholder GameObject which is continually updated every coulpe of seconds, whenever I receive a new message from the server.
if what you want is the same as clicking on the Edit->Undo menu (or as you put, undo the last operation that was applied by the editor), use below code:
Undo.PerformUndo();

Storing functions in an array, or alternative method

I am writing a program in swift for iOS. I have a node with several child nodes organized size by side.
I have two different functions that change the position of these nodes.
One moves the left node over to the right side, and the other moves all the nodes together towards a certain point (because one node was 'removed')
The problem is that these calls are done asynchronously. One is done with the rendering, the other is done after user interaction. And so, when the user does an interaction AND there is a movement in the sliding node, they interfere with each other.
My solution was to store both functions in an array and then call them in the 'update' event. Each function 'locks' the node so that the other function won't be called until it is complete.
My question is, how do I store and execute these functions in Swift.
I have
var actionQueue:[(()->())]
in the head of my class.
But how do I add the function?
actionQueue.append(shiftNodesTowards(position: CGPoint))
And how do I execute?
if !positionLock && actionQueue.count > 0 {
var toDo = actionQueue.removeAtIndex(0)
}
Thank you!
You don't have to to something complicated like that. Just lock the user-input until the non-interactive action is done with beginIgnoringInteractionEvents:
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
//call after your method is done:
UIApplication.sharedApplication().endIgnoringInteractionEvents()