<?xml version="1.0"?>
<ownershipDocument>

    <schemaVersion>X0206</schemaVersion>

    <documentType>3</documentType>

    <periodOfReport>2016-03-30</periodOfReport>

    <noSecuritiesOwned>0</noSecuritiesOwned>

    <issuer>
        <issuerCik>0001597313</issuerCik>
        <issuerName>ViewRay, Inc.</issuerName>
        <issuerTradingSymbol>VRAY</issuerTradingSymbol>
    </issuer>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0001055951</rptOwnerCik>
            <rptOwnerName>ORBIMED ADVISORS LLC</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerStreet1>601 LEXINGTON AVENUE</rptOwnerStreet1>
            <rptOwnerStreet2>54TH FLOOR</rptOwnerStreet2>
            <rptOwnerCity>NEW YORK</rptOwnerCity>
            <rptOwnerState>NY</rptOwnerState>
            <rptOwnerZipCode>10022</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isDirector>1</isDirector>
            <isOfficer>0</isOfficer>
            <isTenPercentOwner>1</isTenPercentOwner>
            <isOther>0</isOther>
            <officerTitle></officerTitle>
            <otherText></otherText>
        </reportingOwnerRelationship>
    </reportingOwner>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0001432241</rptOwnerCik>
            <rptOwnerName>OrbiMed Capital GP III LLC</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerStreet1>601 LEXINGTON AVENUE</rptOwnerStreet1>
            <rptOwnerStreet2>54TH FLOOR</rptOwnerStreet2>
            <rptOwnerCity>NEW YORK</rptOwnerCity>
            <rptOwnerState>NY</rptOwnerState>
            <rptOwnerZipCode>10022</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isDirector>0</isDirector>
            <isOfficer>0</isOfficer>
            <isTenPercentOwner>1</isTenPercentOwner>
            <isOther>0</isOther>
            <officerTitle></officerTitle>
            <otherText></otherText>
        </reportingOwnerRelationship>
    </reportingOwner>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0001055949</rptOwnerCik>
            <rptOwnerName>ISALY SAMUEL D</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerStreet1>601 LEXINGTON AVENUE</rptOwnerStreet1>
            <rptOwnerStreet2>54TH FLOOR</rptOwnerStreet2>
            <rptOwnerCity>NEW YORK</rptOwnerCity>
            <rptOwnerState>NY</rptOwnerState>
            <rptOwnerZipCode>10022</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isDirector>0</isDirector>
            <isOfficer>0</isOfficer>
            <isTenPercentOwner>1</isTenPercentOwner>
            <isOther>0</isOther>
            <officerTitle></officerTitle>
            <otherText></otherText>
        </reportingOwnerRelationship>
    </reportingOwner>

    <nonDerivativeTable>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common Stock</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>7914545</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>I</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value>See footnote</value>
                    <footnoteId id="F1"/>
                    <footnoteId id="F3"/>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common Stock</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>75371</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>I</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value>See footnote</value>
                    <footnoteId id="F2"/>
                    <footnoteId id="F3"/>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
    </nonDerivativeTable>

    <derivativeTable></derivativeTable>

    <footnotes>
        <footnote id="F1">These securities are held of record by OrbiMed Private Investments III, LP (&quot;OPI III&quot;). OrbiMed Capital GP III LLC (&quot;GP III&quot;) is the sole general partner of OPI III, and OrbiMed Advisors LLC (&quot;Advisors&quot;) is the managing member of GP III. Samuel D. Isaly (&quot;Isaly&quot;), a natural person, is the managing member of and owner of a controlling interest in Advisors. By virtue of such relationships, GP III, Advisors and Mr. Isaly may be deemed to have voting and investment power over the securities held by OPI III and as a result may be deemed to have beneficial ownership over such securities.</footnote>
        <footnote id="F2">These securities are held of record by OrbiMed Associates III, LP (&quot;Associates III&quot;). Advisors is the sole general partner of Associates III. Mr. Isaly is the managing member of and owner of a controlling interest in Advisors. By virtue of such relationships, Advisors and Mr. Isaly may be deemed to have voting and investment power over the securities held by Associates III and as a result may be deemed to have beneficial ownership over such securities.</footnote>
        <footnote id="F3">This report on Form 3 is jointly filed by GP III, Advisors, and Mr. Isaly. Each of the Reporting Persons disclaims beneficial ownership of the securities reported herein for purposes of Rule 16a-1(a) under the Securities Exchange Act of 1934, as amended (the &quot;Exchange Act&quot;), except to the extent of its or his pecuniary interest therein, if any. The Reporting Persons have designated a representative, currently David Bonita (&quot;Bonita&quot;), an employee of Advisors, to serve on the Issuer's board of directors. This report on Form 3 shall not be deemed an admission that any of the Reporting Persons or Bonita is a beneficial owner of such securities for the purpose of Section 16 of the Exchange Act, or for any other purpose.</footnote>
    </footnotes>

    <ownerSignature>
        <signatureName>/s/ OrbiMed Capital GP III LLC</signatureName>
        <signatureDate>2016-03-30</signatureDate>
    </ownerSignature>

    <ownerSignature>
        <signatureName>/s/ Samuel D. Isaly</signatureName>
        <signatureDate>2016-03-30</signatureDate>
    </ownerSignature>

    <ownerSignature>
        <signatureName>/s/ OrbiMed Advisors LLC</signatureName>
        <signatureDate>2016-03-30</signatureDate>
    </ownerSignature>
</ownershipDocument>
