We carry out global three-dimensional radiation hydrodynamical simulations of self-gravitating accretion discs to determine if , and under what conditions , a disc may fragment to form giant planets . We explore the parameter space ( in terms of the disc opacity , temperature and size ) and include the effect of stellar irradiation . We find that the disc opacity plays a vital role in determining whether a disc fragments . Specifically , opacities that are smaller than interstellar Rosseland mean values promote fragmentation ( even at small radii , R < 25 AU ) since low opacities allow a disc to cool quickly . This may occur if a disc has a low metallicity or if grain growth has occurred . With specific reference to the HR 8799 planetary system , given its star is metal-poor , our results suggest that the formation of its imaged planetary system could potentially have occurred by gravitational instability . We also find that the presence of stellar irradiation generally acts to inhibit fragmentation ( since the discs can only cool to the temperature defined by stellar irradiation ) . However , fragmentation may occur if the irradiation is sufficiently weak that it allows the disc to attain a low Toomre stability parameter .