Why make another variable?

If we already have a use case for what to do if selectedDialogue is null why can’t we just cast Selection.activeObject as Dialogue directly into selectedDialogue? The way it’s done in the lecture is by casting it to a new variable called newDialogue and then checking. But then doesn’t the check in OnGUI() become redundant?

I’m just curious, is it like bad practice or something? It works fine when I tried it. Is it less performant?

1 Like

If you use this method, then when you select something that isn’t a dialogue, selectedDialogue will become null, and the editor will not have a dialogue to display. One of the principle advantages of an EditorWindow over a standard Editor is that we have more control over selection, so we can do things like work on the Dialogue while also selecting Dialogue Nodes to work with in the inspector.

1 Like

I see! Thank you, I was a little confused but this cleared things up :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms