How do you perform a Graphic Raycast?

I need to perform a raycast to detect a UI object with no collider. It appears this is how the event system works according to this page…


I’ve performed a physics raycast before, but this one is new for me. What is the syntax to perform a graphic raycast?

Thank you!

//Code to be place in a MonoBehaviour with a GraphicRaycaster component
GraphicRaycaster gr = this.GetComponent();
//Create the PointerEventData with null for the EventSystem
PointerEventData ped = new PointerEventData(null);
//Set required parameters, in this case, mouse position
ped.position = Input.mousePosition;
//Create list to receive all results
List results = new List();
//Raycast it
gr.Raycast(ped, results);

No worries at all. Yes, I believe I figured it out. This is the code I’m using…

		PointerEventData cursor = new PointerEventData(EventSystem.current);							// This section prepares a list for all objects hit with the raycast
		cursor.position = Input.mousePosition;
		List<RaycastResult> objectsHit = new List<RaycastResult> ();
		EventSystem.current.RaycastAll(cursor, objectsHit);
		int count = objectsHit.Count;
		int x = 0;

In fact, I already have a script package on the Asset Store. It allows for actions such as moving and resizing UI objects at runtime. The reason I needed the raycast was so multiple scripted objects would play well together… only the fore-most object’s script would be affected by a mouse-drag. You can actually test it in the following demo. Just click the “Multiple Windows” button.

Here are two web demos the scripts in action so far…



I’m actually hoping to update it within a few days with the ability to use custom cursors when the cursor is over a moveable/resizable position… which also uses the raycasting. It would have been updated already, but I keep thinking up new features to add.

The next update will include a script to minimize, maximize, and restore an object. It will also include a script that allows one object to push or pull another object’s position or specific edge. And I have also added the ability to restrain objects so they remain on the screen or inside their parent.

Here is the link to the asset…
Move & Resize UI

I am still quite the newbie, so I’m sure the scripts are nowhere near perfect, but I’ve learned so much already. The whole reason for this project was because I’m an old-school Morrowind fan. I absolutely love that game! So I wanted a way to make a user interface that is so user-friendly and customizable. So with these scripts, I’m coming much closer to my goal. I actually ALMOST have a working replica of an inventory menu! :smiley:

Not for the topic owner. But in fact @batmobile is the one that said what i was looking to know, Shady. How to use this without EventSystem, it was be so simple…

Not for the topic owner. But in fact @batmobile is the one that said what i was looking to know, Shady. How to use this without EventSystem, it was be so simple…