Depending of drag and drop operation from anchor position in unreal engine 4 - drag-and-drop

I have the problem with Drag-and-Drop Operation for UI elements:
i have created a test object to drag: DragTestObject_BP and have override the functions:
OnMouseBottonDown Function and OnDragDetected.
Recepient will be HUD_BP with overridden is OnDrop function.
The problem is, that first drag-and-drop operation is functioning without problem only, if the anchor for drag object is set for upper left corner. Otherwise the drag object has some wired offset.
Position on start:
Drag object jumped by first mouse click on it

Might be a bit late, but youll want to put the widget you're clicking to drag ("DragTestObject_BP") inside of another widget.
It's probably a good idea to remove any canvas panel in "DragTestObject_BP" as well.
This will make the origin of "DragTestObject_BP" where it is located visually, instead of using the location of the canvas panel which is the issue you seem to have run into.

Related

How do you set Toggle UI interactable size manually in Unity?

I'm trying to make a toggle UI like the one on this youtube(https://www.youtube.com/watch?v=mQTnB71NUAw&ab_channel=MaxShakurov").
This example uses a button UI to make this happen. But I'm trying to make it with a toggle UI that Unity provides.
But here is the problem that I faced.
Issue: There is a big difference in the interactable box size of what I expected.
Below is an example to make it easy to reproduce.
My Unity version: 2018.4.23f1
I created a new project.
I added a default toggle UI
---> There is a big difference between my expectation of interactable box size and the actual one.
My initial expectation was to make toggle UI to be able to interact with the size of its' target graphic.
How can you make a toggle UI to be able to interact on only the size of a target graphic?
The interaction space is expanded to any child object having a graphic element (Image, Text, etc) with Raycast Target enabled.
All you have to do is
Go to the Label object in the Hierarchy
Go to the Text component in the Inspector
Disable the Raycast Target checkbox
As a result you should now have only the checkbox itself interactive

How do you sort UI elements in Canvas?

I don't get how you sort UI elements Z-index in Unity inside a Canvas, is it by hierarchy order ?
I'm trying to do a settings screen like in this video: https://www.youtube.com/watch?v=-qNo1jloR_k
It's quite simple, you click on the button and it set the whole panel as first sibling in the hierarchy.
But this is what I get:
https://gyazo.com/cec14f21df2ded191875e6a8cfd9f124
Also, my gameplay panel had a red background, my graphics panel a green one, and my sound panel a yellow one.
I could avoid this problem by changing alpha on panels, but would like to make it work with z sorting... that I can't seem to understand on Unity.
Using unity 2017.1.2 and .NET 4.6 .
The child that is lower in the hierarchy is rendered on top of other ones.
Let's say there are 2 panels. panel1(red) and panel2(green).If the hierarchy is like this:
-panel1
-panel2
Then panel2 will be rendered on top of panel1. So, you'll see green panel.
Hope this answers your question.
Another suggestion, it is better to deactivate the unused panels and activate only the used panels. Because, if the unused panel is active, when it's not shown, it'll still take the processing power which is a waste. For example, if you have animation in the main menu, but currently you are showing the settings panel, your approach will keep the animations running in the main menu.

How to implement a 'dynamic' drag and drop (like iOS/Android)?

I would like to implement a 'dynamic' drag and drop in a list. By 'dynamic' I mean that in the list in which the drag is happening, there's an empty space below the dragged element which 'follows it' as you drag through the list (to make it visually obvious where the dropped element will end up in the list). Like what you see in iOS/Android apps supporting D&D.
What I've tried is to use Component.dragEnter to insert an empty Component with the size of the dragged element below the dragged compoment. And as the drag moves through the list, remove the old Component and insert a new one in the new position (explanation of why I create a new Component in next paragraph). However, with the dynamic updates that CN1 does while dragging, and my own updates when moving the empty Component, I just cannot find a way to make it work so I get the right vusual behavior. One aspect making this more complex than you'd think at first is that CN1's built-in support for drag&drop makes the original dragged component invisible with setVisible(false) which means it leaves an empty space behind.
The reason I recreate a new empty Component is because the final drop() will happen on the empty Component, and my trick to make this work is to override drop() on the empty Component to call drop on the dropTarget that is (was) in the Component's position.
All in all, I've spend I don't know how many days trying to get this to work with no success so far. Let me know if anyone has a suggestion for a more straightforward approach?
Big thanks in advance!
The builtin support hides the original component but drags an image of it which you can customize by overriding getDragImage().
You can use custom code to highlight the drop location by using a drag over listener which you can accomplish by using addDragOverListener(ActionListener).

Gui text does not display

I am using unity 4.6 to develop a small game.
There is no gui text object in the menu. Therefore I created an empty object and added gui text as a component. But it does not display the text I type. Need help on this. Thank you
I think that 4.6 is when they introduced the new UI system so you can use that.It is actually pretty easy...from the drop down menu that you created the game object go to UI. There you can select from a number UI options one of witch is Text or UI Text if my memory serves me well. When you click it it will create a canvas object and UI Text object that is a child of the Canvas.From here just select the Text object and in the inspector you have a textbox which should serve your need :) Also the Canvas is your screen in the sense that if you drag your text to the top left corner of the Canvas(in the scene view) your text will be in the top left corner of the screen when you start your game(at least in the default settings). Hope that helps!
P.S. Also here is a link to the new UI article that the Unity guys have on their site: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui
That happens sometimes. Delete the current gameobject and the guitext in the scene. Do what you did backwards.
Create a new guitext then create a new empty gameobject. Change the transform of the empty gameobject to 0,0,0 then drag the new gui text into the empty gameobject.
That should solve your problem.
The default text you should see if that went well is "New Text".
If you are editing the new text in the text area and it stopped showing, you will need to increase the width and sometimes the Height of the guiText. Don't use the scale tool as that will work but the graphics you get will be low quality text rendering on the screen.

Scroll to the dropped object when it's released outside of the current view of a GEF editor

I have a GEF editor with draggable figures. I have overriden the createChangeConstraintCommand of the main EditPart's XYLayoutEditPolicy.
This allows me to easily move (drag and drop) the figures.
The problem is, that if I drag one of them outside of the current view, although the scroll appears and the figure is moved, the view does not automatically scrolls to the dropped object.
Any idea how to implement this "auto-scroll" functionality? (It would be even nicer to have the "selected" (dragged/dropped) figure always visible in the view.)
Given the editpart object that has been dropped, you should use EditPartViewer#reveal(EditPart) method. Do this for example:
editpart.getViewer().reveal(editpart)