Jump to content

Code not working, cant change mun's textures/heightmap


Recommended Posts

This code is based off of some code from NovaSilisko's mod, Alternis Kerbol, but I cant figure out whats wrong

		
public CelestialBody Mun;
public CelestialBody Kerbin;
public Texture2D MunColor;
public Texture2D MunHeight;
public Texture2D MunBump;

private string path = "HappyFaceIndustries/Crap/Textures/";

public void ChangeHeightMap(Texture2D map, CelestialBody cb, float deformity, double heightMapDeformity, double heightMapOffset)
{
GameObject OldHeight = cb.pqsController.transform.FindChild("_Height").gameObject;
if (OldHeight != null)
{
//sets deformity
foreach (PQSMod_VertexHeightNoiseVertHeightCurve2 c in OldHeight.GetComponentsInChildren<PQSMod_VertexHeightNoiseVertHeightCurve2>())
{
c.deformity = deformity;
}
//creates VertexMap
PQSMod_VertexHeightMap VertexMap = OldHeight.GetComponent<PQSMod_VertexHeightMap>();
//edits VertexMap, sets height map
if (VertexMap != null && map != null)
{
VertexMap.heightMap.CreateMap(MapSO.MapDepth.Greyscale, map);
VertexMap.heightMapDeformity = heightMapDeformity;
VertexMap.heightMapOffset = heightMapOffset;
}
if(map = null)
{Debug.Log("Crap: map null...");}
}
}

public void ChangeColorMap(Texture2D color, /*Texture2D bumpMap,*/ CelestialBody cb, float blend)
{
//sets color map
PQSMod_VertexColorMapBlend OldColor = cb.transform.GetComponentInChildren<PQSMod_VertexColorMapBlend>();
if (OldColor != null)
{
OldColor.vertexColorMap.CreateMap(MapSO.MapDepth.RGB, color);
OldColor.blend = blend;
}
//sets color noise
PQSMod_VertexSimplexNoiseColor oldColorNoise = cb.transform.GetComponentInChildren<PQSMod_VertexSimplexNoiseColor>();
if (oldColorNoise != null)
{
oldColorNoise.order = OldColor.order + 1;
oldColorNoise.blend = 0.1f;
}
//sets scaledspace maps
foreach (Transform t in ScaledSpace.Instance.scaledSpaceTransforms)
{
t.gameObject.renderer.material.SetTexture("_MainTex", color);
}
}
public void Awake()
{
MunColor = GameDatabase.Instance.GetTexture(path + "MunColor", false);
MunHeight = GameDatabase.Instance.GetTexture(path + "MunHeight", false);
}

public void Start()
{
foreach(CelestialBody CB in FlightGlobals.Bodies)
{
if(CB.name == "Mun")
Mun = CB;
}
//Mun
Mun.orbitDriver.orbitColor = XKCDColors.ReddishBrown;
ChangeHeightMap(MunHeight, Mun, 700f, 1400d, -2000d);
ChangeColorMap(MunColor, Mun, 1f);
}

When i run KSP, it gives me this error:

NullReferenceException: Object reference not set to an instance of an object

at Crap.BaseCrap.ChangeColorMap (UnityEngine.Texture2D color, .CelestialBody cb, Single blend) [0x00000] in <filename unknown>:0

at Crap.BaseCrap.Start () [0x00000] in <filename unknown>:0

;.;

Edited by MrHappyFace
Link to comment
Share on other sites

Well, you're not checking either MunColor or MunHeight for null before you use them in Start(). I'd start there.

Thanks for the quick reply, ill try that. another related question: what is the error message mean?

EDIT: i added this:

Debug.Log("Crap: Changing mun...");
Mun.orbitDriver.orbitColor = XKCDColors.ReddishBrown;
if(MunHeight != null)
{
ChangeHeightMap(MunHeight, Mun, 700f, 1400d, -2000d);
}
else
Debug.Log("AndrewCrap: MunHeight = null...");
if(MunColor != null)
{
ChangeColorMap(MunColor, Mun, 1.0f);
}
else
Debug.Log("Crap: MunColor = null...");

And it still sadi the same debug message, but didnt say that MunColor or MunHeight were null either

Edited by MrHappyFace
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...