#scenefield

1 messages · Page 1 of 1 (latest)

torn pebble
#

threaded for clarity

#

SceneField is not a scene

vestal bronze
#

right

torn pebble
#

it's just a convenient way to store the name of one correctly

#

you will need to use the usual SceneManager methods to actually grab the Scene reference

vestal bronze
torn pebble
#

previously, you had no way to configure what scene you want through the inspector

#

this lets you identify the scene

#

the actual Scene object can only be retrieved if that scene is currently loaded

#

you can use that method to grab the Scene object if it has been loaded

#

I believe there is a distinction between the scene asset on disk

#

and the Scene type that you use with SceneManager

vestal bronze
#

sorry for delay, called for dinner

#

@torn pebble would this solution work?

private Scene Play;

void Update()
{
Play = SceneManager.GetSceneByName("Play");

if(Play.isLoaded)
{
SceneManager.MoveGameObjectToScene(gameObject,Play);
}
}
torn pebble
#

Yeah, although one thing to note: you can only get a scene by name if it's loaded

#

I'm a little fuzzy on that -- not sure why the field even exists, then..

#

you can call IsValid() on the Scene to check if it's a valid Scene

vestal bronze
#
        if(Play.IsValid())
        {
        Play = SceneManager.GetSceneByName("Play");
        }
```?
torn pebble
#

"got destroyed"?

#

that would probably throw a NullReferenceException

vestal bronze
torn pebble
#

things don't get destroyed because they threw an error

vestal bronze
#

Sorry, my bad.

#

That didnt quite work either, now im really stumped.

torn pebble
#

show me your code

#

i should probably back up and ask what you're doing here

vestal bronze
torn pebble
#

oh, you just want to get a value?

#

then you don't need any of this

vestal bronze
vestal bronze
torn pebble
#

you can either:

  • put it in a static field
  • call DontDestroyOnLoad() on an object to prevent it from being destroyed when changing scenes
#

you got XY problem'd :p

vestal bronze
#

as for static, is this correct?

public static float spawnSpeed;
torn pebble
#

Right. That field is now associated with the class itself, instead of an instance of the class

#

Anyone can read it as ClassName.spawnSpeed;

#

whatever ClassName is

vestal bronze
#

let me try the new solution

torn pebble
#

it's good to ask about what you want to do, rather than what you think you need to do (:

#

I spent like 90 minutes yesterday figuring out how to get full-screen post processing working in the URP in VR

vestal bronze
torn pebble
#

I then realized that the effect I wanted looked horrible that way

#

and I just needed to change the brightness of a material when an objected appeared

vestal bronze