Why m_LayerHit and M_hit

Why not just make m_layerHit and m_hit public. Why use layerHit and hit with a get? Could be i’m just not familiar with get.

I’m assuming that’s because in other classes you don’t want to give the option to (accidentally) change layerHit and hit, but you do want to be able to change it in our CameraRaycaster class.

Why we’re not using a public getter with a private setter like so I’m not sure:

public layerHit 
{
    get;
    private set;
}

Maybe @ben can expand on this :slight_smile:

You could do that, but it would be like going to the front door then going to the kitchen. If you are already in the house, just go to the kitchen. A property is like the door, so unless it makes sense to allow people to have access to set that variable from outside the class, then making it readonly by only defining the getter portion makes the most sense, and is the most performant. As you can see from my example going to the kitchen, or going to the front door then go to the kitchen, you can see just going to the kitchen is more performant. By using the public property to set a private setter adds one more call to the stack. Hope that helps.

This needs some further work when we next loop round to it. Another option is to create explicit boolean methods such as bool IsLayerHitEnemy(). I’ll take a look when we’re next there.

I didn’t finish the unreal course can I have a link to the get rant?

Privacy & Terms