#Can you try distilling this question

1 messages ยท Page 1 of 1 (latest)

worldly frigate
#

@thorny thistle Having UI interact with in-game visual objects. There's a quick example as an image. Currently putting in a red tinted spot light darkens the game and only illuminates that area but the buttons are completely unaffected.

thorny thistle
#

UI is not going to be affected by in-game lighting or whatever those things are

#

it's unclear what your "red-tinted-spot" is made of

worldly frigate
#

Oh that's jus ta 2d light object

thorny thistle
#

you would need to use SpriteRenderers to be affected by that

worldly frigate
#

And yeah, UI is hard to work out since that little black box bottom left is the game area, but you can see the very bottom of the UI that's huge (referencing 1080x1920 on canvas)

thorny thistle
worldly frigate
#

Not sure if I can reconcile both of them to properly overlay ๐Ÿคทโ€โ™‚๏ธ

thorny thistle
#

it's shown in the scene as 1 pixel = 1 unit

#

that's just how it looks in the scene view though

worldly frigate
#

Yeah in game looks solid

#

Just hard to figure out what area I have left to work with

thorny thistle
#

well you shouldn't be trying to line screen space UI up with world space objects

#

that will break anyway as soon as the game aspect ratio or resolution changes

worldly frigate
#

Fair point, so when you say I shouldn't be using UI, what would be the next best thing?

thorny thistle
worldly frigate
#

Ah my bad didn't recognise that was the solution, thought it was a workaround

#

My original reasoning for going the UI path was to simplify User input cross devices (mostly targeting mobile) Any idea if that would be a challenge or not overly concerning?

thorny thistle
#

user input? Not a concern

#

You can use the same input mechanism UI has on game world objects

#

Just use scripts with IPointerClickHandler, give the sprites collider2ds, include an EventSsytem in your scene, and a GraphicRaycaster2D on the camera

worldly frigate
#

So game world objects that must be clicked will have a Monobehaviour also implement IPointerClickHandler, they will obviously have the appropriate collider.

I'm hoping ๐Ÿคž the EventSystem I bring in from a separate scene would work just fine for this use case (on new input system, I know having multiples conflict or at least spam warnings) and I swear I saw a GraphicRaycaster2D before but.. can't find now on my camera ๐Ÿซ 

#

Ah, it's the canvas I saw the Graphic Raycaster on, not the camera

thorny thistle
#

Oh sorry I meant PhysicsRaycaster2D

#

you need that on the camera

worldly frigate
#

For Cinemachine, that would be on the VCam, correct? Or still the MainCamera itself?

thorny thistle
#

actual camera

worldly frigate
#
    public class GameWorldClickHandler : MonoBehaviour, IPointerClickHandler
    {
        [SerializeField] private UnityEvent onClick;
        
        public void OnPointerClick(PointerEventData eventData)
        {
            onClick?.Invoke();
        }
    }

Something like this to emulate similar OnClick logic to the usual UI Buttons?

#

๐Ÿ™Œ

#

@thorny thistle It worked... but not fully ๐Ÿ˜ฆ I put a cheeky comment to confirm it working but it only ever printed once:

        [SerializeField] private UnityEvent onClick;
        
        public void OnPointerClick(PointerEventData eventData)
        {
            onClick?.Invoke();
            Log.Info("We got clicked boi");
        }
thorny thistle
worldly frigate
#

My bad, the count remained 1

#

BUT after a while it did increase to two, and after clicking several dozen times it's now 4... It works, but something is a bit weird?

#

Oh... so it's something collider related. If I click the very top of the circle it works every time, just like a button would. But for most of the circle it doesn't.

Collider has no offset with a slightly bigger 0.7 radius... I'm going to assume it's because I scaled the circle? Does that throw off the collider?

#

Scaling back to 1 didn't fix anything, it seemed to make it worse. I can click only very specific spots in the circle, even when scaled up

#

I'll test a plain main camera instead of cinemachine

thorny thistle
#

a ui element or another collider

thorny thistle
#

cinemachine literally just positions your camera

#

it does nothing else

worldly frigate
#

Thanks, from what I can tell... clickicking on the actual circle doesn't work, but just outside of it (that extra overlap I gave it from a bigger radius) seems to work. So it's the sprite itself interfering somehow? Doesn't make sense to me since the collider should be shared

#

Tried moving the sprite lower but it must be as you said, something else is capturing these clicks somehow. I'll try a plain scene just to test the logic for now

worldly frigate
#

Still no luck. Tried a dedicated scene with barely anything in there and I'm unable to even get it to show the message once now ๐Ÿ˜ฆ

#

@thorny thistle If I could bother you again just in case you have any idea what to try ๐Ÿ˜… I'm completely clueless at this point