Exhibit 5.1

Karen E. Anderson
+1 858 550 6088
kanderson@cooley.com
December 12, 2018
Tocagen Inc.
4242 Campus Point Court, Suite 500
San Diego, CA 92121
Ladies and Gentlemen:
We have acted as counsel to Tocagen Inc., a Delaware corporation (the “Company”), with respect to certain matters in connection with the offering by the Company of up to 3,450,000 shares of its common stock, par value $0.001 (the “Shares”), including up to 450,000 shares that may be sold pursuant to the exercise of an option to purchase additional shares, pursuant to the Registration Statement onForm S-3(No. 333-224880) (the “Registration Statement”) filed with the Securities and Exchange Commission (the “Commission”) under the Securities Act of 1933, as amended (the “Act”), the prospectus included within the Registration Statement (the “Base Prospectus”), and the prospectus supplement dated December 12, 2018 and filed with the Commission pursuant to Rule 424(b) of the Rules and Regulations of the Act (the “Prospectus Supplement”). The Base Prospectus and Prospectus Supplement are collectively referred to as the “Prospectus.” All of the Shares are to be sold by the Company as described in the Registration Statement and the Prospectus.
In connection with this opinion, we have examined and relied upon the Registration Statement and the Prospectus, the Company’s Amended and Restated Certificate of Incorporation, its Amended and Restated Bylaws and the originals or copies certified to our satisfaction of such records, documents, certificates, memoranda and other instruments as in our judgment are necessary or appropriate to enable us to render the opinion expressed below.
Our opinion herein is expressed solely with respect to the Delaware General Corporation Law. We express no opinion to the extent that the laws of any other jurisdiction are applicable to the subject matter hereof. We are not rendering any opinion as to compliance with any federal or state antifraud law, rule or regulation relating to securities, or to the sale or issuance thereof.
On the basis of the foregoing, and in reliance thereon, we are of the opinion that the Shares, when sold and issued in accordance with the Registration Statement and the Prospectus, will be validly issued, fully paid andnon-assessable.
Cooley LLP 4401 Eastgate Mall San Diego, CA 92121
t: (858)550-6000 f: (858)550-6420 cooley.com