I was just trying to make a script that assigned a volume profile for my scenes. It looks like it works but then it when I open the same scene back up, it’s as though it’s never been assigned.
Does anyone know what I’m doing wrong? If I manually assign it works fine.
I did notice that next to the variable in the editor it comes up with (instance), could that have something to do with it?
Thanks!
Pete
public Volume volume;
public VolumeProfile volumeProfile;
private void OnValidate()
{
if (doIt)
{
doIt = false;
volume.profile = volumeProfile;
}
}
Where are you getting that VolumeProfile instance from. It might be what isn’t already saved to the scene… it’s subtle how assets are glommed together, and if something is not saved to disk then references to it also cannot be saved to disk.
It’s also order dependent. If you create a Material, assign it to a Renderer, THEN write the Material to disk, the reference in the Renderer will not serialize.
But if you write that same exact Material as an asset on disk first, THEN you can use it all day long in scenes / prefabs and it will persist as long as you dirty the ref.
Thanks Kurt,
The profiles have been saved earlier and are just sitting in the project. In the gif you can see the reference is assigned in the top script and it’s just trying to assign that to the volume script. I thought that (Instance) message might be a clue but I’m really not sure.
I made it into a little package that I might send off to support, if you feel like having a look (but no worries if not).
Was about to write similar, as I noticed the ‘(Instance)’ comes up when you hit the check box, implying you’re putting a transient copy of what looks like a scriptable object into the ‘Profile’ Field.
Also this seems to be a rather awkward way to do editor scripting, if that’s what you’re doing?
Hey Spiney,
The volume profiles are scriptable objects. So I just have one referenced that I want to apply to the volume through a script.
Oh yeah, and the script is pretty rough, I’m just trying to simplify it as much as possible to rule out anything else causing it to break.
That’s a Unity component @spiney . It’s just how they handle post processing in URP.
I think I have it! I switched to debug mode -
Looks like shared profile is the one, I was setting the wrong thing Yeay!
Thanks for the help!
P
public Volume volume;
public VolumeProfile volumeProfile;
public bool doIt;
private void OnValidate()
{
if (doIt)
{
doIt = false;
volume.sharedProfile = volumeProfile;
EditorUtility.SetDirty(volume);
}
}