Be the first to post for 'Fully Event Based Raycasting'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

1 Like

@ben These latest lectures are out of order. I believe this one was meant to come before the pathfinding lectures :slight_smile:

Just got to this lecture and i have an issue of the origin i am not sure.
When ben clicks after the changes it complains that a gameobject has not been assigned.
I get this same error from the below code in CameraRaycaster.cs (line 25 has the error)

        // Check if pointer is over an interactable UI element
        if (EventSystem.current.IsPointerOverGameObject ())
        {
            NotifyObserersIfLayerChanged (5);
            return; // Stop looking for other objects
        }

If this is left in i get the error reoccuring and the cursors do not work. If i comment just this out everything works as expected.
Can anyone tell me what i have missed?

Edit :-
Dont get distracted!
Forgot to add the event system in unity.

1 Like

Also sorted now Marc? :slight_smile:

Actually strangely enough thats actually written correctly :slight_smile:
The isasue was the little tykes had decided to argue on minecraft whilst ben added an event system into unity.
I think because it was done before the challenge slide i kept missing what was done as did not expect it added before that.
All working now (aside from my camera glitch but WIP)
Thanks @Rob

1 Like

Actually strangely enough thats actually written correctly :slight_smile:

Sorry, didn’t mean to quote that in my post to you - I had copied that to bring to Ben’s attention, the forum “helpfully” quoted it! lol

All working now

Awesome :slight_smile:

This won’t come as a surprise but I couldn’t figure out the challenge. :slight_smile:

2 Likes

Most of the challenge was fine but I would have never guessed ( and didn’t obviously ) to use a SerializeField annotation and grabbing the actual real number of the layer. Also you referred to the process several times as ‘parameterizing’ so I was looking for something completely different.

2 Likes

This is my second time attempting the course, and I am starting to consider myself fairly proficient with C# basics now, so I don’t know if my feedback represents a typical user… but I didn’t have any trouble with this challenge at all. I feel like the Complete Unity Developer course, as well as supplementary tutorials I’ve done elsewhere, has left me well prepared. I don’t feel intimidated by challenges like this, even if I’m not completely confident in my use of delegates yet. (I probably won’t be until I code something myself with them. In the meantime, seeing practical ways to use them is helpful.)

If you’re taking requests, I’d like to learn Dictionaries at some point. I did once or twice before, but I didn’t use the knowledge and it’s all gone now.

1 Like

I found this ‘challenge’ to be extremely frustrating due to not enough (and unclear) guidance on the exact nature of the task.

I ended up getting completely lost, and over complicating things by introducing a Dictionary to ‘parameterize’ the layer integers.

Also my CameraRaycaster component (even after I’d gotten rid of all the errors) wasn’t populated with the two required layers (Walkable and Enemy). It took me forever to work out that I had to add them myself (in the custom inspector). Not sure why Ben’s was automatically populated with the two required layers, and not mine.

1 Like

Can’t you just use “[SerializeField] LayerMask layers[]” and let Unity create Layer drop-downs for you?

If you please update this part of the lecture later, please slow down the transition in lecture 44; or find a way to modify the files / not completely replacing them.

I had modified CameraRayCaster.cs and CursorAffordance.cs codes by myself in challenge sections. But in this lecture, imported the new CameraRayCaster.cs, and boom! so many errors and totally lost.

I’m currently having similar issues.

I’d already built quite a bit of additional functionality on top of the original architecture, so this one has introduced a massive amount of re-work for me.

Perhaps some warnings should be added to the earlier sections to let us know if a particular bit of functionality gets re-architected later?

But Ben did tell us quite a bit ago that stuff will get revamped basically. I did not like the initial raycaster that much, and I’ve always abused the Unity Graphical Raycaster + My own Input Module, but this event based one looks really cool. I knew about events but just now realise how awesome they are.

Just a little bit of feedback - I struggled with this too and it was because of the above - however that said I thought the rest of the lecture was very clear and I do understand the concept of whats happening here. So for the majority, good job @ben

The problem I’ve had with this is that Ben said you shouldn’t have to manually add them - it is supposed to pick up the layers list itself, which was the whole point of changing the architecture.

The challenge itself was ok, but not being able to get this working is frustrating me to no end :confounded:

I can’t see anywhere were the int[] layerPriorities is getting assigned it’s values…

I’m attempting the challenge now and it’s mainly some of Ben’s terminology that’s confusing me. He said that we need an integer based layer system, but then right afterwards said we shouldn’t be using “magic numbers”, so I’m confused: do we use numbers or don’t we???
[EDIT]: Or to phrase it better — if all we are doing is serialising our layer integers with special variable constants,
I don’t see how that’s a whole lot better than that enum we just worked hard to eliminate. I would use something like LayerMask.NameToLayer(“Walkable”), etc. somewhere one time at execution to store those values. Calling string tables once or twice at initialization is not going to kill your performance, as long as you don’t ever do it in an Update method or ever get components using strings. Granted, switch statements don’t work with this, but I would personally sacrifice few milliseconds of efficiency for robustness.

Also, when I finished the challenge I also got movement working again by turning ProcessMouseMovement (in PlayerMovement) into a listener for the OnClickPriorityLayer delegate and turning the first parameter of that delegate into “RaycastHit?” (and made use of hit.Value.point as needed). Though I assume Ben has a better way to handle this later.

I think that last part is new editor code he’s covering after this.

Great video! People need to be exposed to ugly code refactoring. It is an essential experience for any type of programming work, and will make you think twice before doing it or not doing it on a million dollar application :laughing:

Privacy & Terms