To check whether an object or any variable exists (i.e., is instantiated) in SystemVerilog, you can simply compare it to null. SystemVerilog treats uninstantiated or undeclared objects as null.
In some cases during a test, you might attempt to access a variable that hasn’t been declared or instantiated, resulting in the well-known null pointer reference error. To avoid this, always check if a variable exists before proceeding with your code.
Example: