- Home /
URP: Instantiating tree instances via code, cannot set properties
I am writing something to place trees on a terrain via code rather than brushing through the terrain editor (using this course as my basis).
This is the idea of how I am creating tree instances:
TreeInstance instance = new TreeInstance();
// stuff that works even in URP
instance.prototypeIndex = prototypeIndex;
instance.position = instancePosition;
// stuff that does not work at all in URP, but works in Standard
instance.color = Color.red
instance.lightmapColor = Color.green
instance.heightScale = UnityEngine.Random.Range(0f,1f);
instance.widthScale = UnityEngine.Random.Range(0f,1f);
instance.rotation = UnityEngine.Random.Range(0, 2 * Mathf.PI);
// add tree to vegetation list
allVegetation.Add(instance);
If I use what I have written in a normal Unity 3D project, all good.
If I try using it in a URP project, the tree instances will be placed at the correct spot, but all other properties (as detailed in the code comment) will stay at their default and not be changed by the code at all (scaling, color, lightmap color...).
My guess is that URP has an altogether different way of doing trees, and/or changing the shader of the tree prototypes to speedshader8 (so that they actually show up on screen) means none of these properties work.
Does anyone have a solution/workaround/explanation/useful link?
The trees I used are free trees meant for Standard rendering, after importing them I converted all shaders to URP, and then manually changed the trees' shaders to URP > Nature > SpeedTree7/8, as that seemed to be the only way to get them to even show up.
I looked for a tutorial or other material explaining how tree rendering works in URP, so that I could learn that and convert my code, but found nothing.
Any help is welcome!