Ok, I've solved.
If an Environment is set in the camera it has the highest priority.
Infact if you push the down arrow. the current env material is not affected in the viewport,
as i've set an environment in the camera.
In the func ready i was trying to set the cube material to null.
It seems i miss something as the only way i've found is to use the set_surface_material to null.
Hope it helps someone.
extends Spatial
var new_material = null
var old_material = preload("res://mat1.material")
var env1 = preload("res://env2.tres")
var env2 = preload("res://default_env.tres")
func _ready():
var old_material= $Cube.get_surface_material(0)
$Cube.set_surface_material(0,new_material)
$Camera.environment= env1
func _process(delta):
if Input.is_action_just_pressed("ui_down"):
$Camera.environment= env2
get_node("WorldEnvironment").environment = env1
$Cube.set_material_override(old_material)
$Sphere.set_material_override(old_material)