Jump to content

OrbitRenderer not showing


Recommended Posts

So i am trying to create an orbit with nothing attached to it, and i followed this thread 

 but i cant get it to work. Here is the code i have:

Object = new GameObject();
Orbit = new Orbit(0, 0, 12000000 * 0.6, 0, 0, 0, 0, FlightGlobals.GetHomeBody());

OrbitDriver = Object.AddComponent<OrbitDriver>();
OrbitRenderer = Object.AddComponent<OrbitRenderer>();
OrbitDriver.orbit = Orbit;
OrbitDriver.orbit.Init();

Vector3d p = OrbitDriver.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
Vector3d v = OrbitDriver.orbit.getOrbitalVelocityAtUT(Planetarium.GetUniversalTime());
OrbitDriver.orbit.h = Vector3d.Cross(p, v);

OrbitDriver.orbitColor = Color.red;
OrbitDriver.updateMode = OrbitDriver.UpdateMode.TRACK_Phys;
OrbitRenderer.driver = OrbitDriver;
OrbitRenderer.SetColor(Color.red);
OrbitDriver.Renderer = OrbitRenderer;

OrbitRenderer.upperCamVsSmaRatio = 999999;
OrbitRenderer.lowerCamVsSmaRatio = 0.0001f;
OrbitDriver.upperCamVsSmaRatio = 999999;
OrbitDriver.lowerCamVsSmaRatio = 0.0001f;

OrbitRenderer.celestialBody = Orbit.referenceBody;
OrbitRenderer.drawIcons = OrbitRenderer.DrawIcons.ALL;
OrbitRenderer.drawMode = OrbitRenderer.DrawMode.REDRAW_AND_RECALCULATE;

OrbitRenderer.enabled = true;
OrbitDriver.drawOrbit = true;

I have a feeling that i am really close to getting it to work, and that there is some silly mistake that breaks everything.

Link to comment
Share on other sites

  • 8 months later...

Any luck yet? I can get an orbit to display, but only in "simple" mode (i.e., single orbit, not multiple patches). And that orbit isn't at all what I expect, the periapsis looks like it's dropped down to 0 despite the whole Orbit object being a direct clone of Kerbin's. Screenshot of the corrupted orbit in simple mode:

68n5vYe.png

Relevant portion of log (patched mode), with some statements added to annotate the coroutine:

[LOG 17:47:11.971] Waiting for end of frame
[EXC 17:47:12.213] NullReferenceException: Object reference not set to an instance of an object
        OrbitRendererBase.CreateScaledSpaceNodes () (at <8ed6226a17824027b61a78aa9c35f6f0>:0)
        OrbitRendererBase.Start () (at <8ed6226a17824027b61a78aa9c35f6f0>:0)
        OrbitRenderer.Start () (at <8ed6226a17824027b61a78aa9c35f6f0>:0)
[EXC 17:47:12.424] NullReferenceException: Object reference not set to an instance of an object
        OrbitRendererBase.LateUpdate () (at <8ed6226a17824027b61a78aa9c35f6f0>:0)
[LOG 17:47:12.430] Nulling vessels...
[LOG 17:47:12.430] Vessels nulled.
[EXC 17:47:12.681] NullReferenceException: Object reference not set to an instance of an object
        OrbitRendererBase.LateUpdate () (at <8ed6226a17824027b61a78aa9c35f6f0>:0)
[EXC 17:47:12.912] NullReferenceException: Object reference not set to an instance of an object
        OrbitRendererBase.LateUpdate () (at <8ed6226a17824027b61a78aa9c35f6f0>:0)
(and then many more of these)

In case it helps anyone else, the example code and links in the forum are out of date; the latest is here:

Link to comment
Share on other sites

Interesting updates. First, this fixed those exceptions and eliminated the extreme stuttering they were presumably causing, so patched mode now works and is butter smooth:

			orbitRenderer.driver = driver;

The orbit still starts out corrupted, but if I re-run the whole process verbatim, it suddenly amends itself to the copy of Kerbin's orbit that I asked for. So there's some kind of mystery state that's set properly the second time but not the first; time to randomly rearrange assignments till it works...

Link to comment
Share on other sites

Next bizarre quirk... none of the below lines do one single solitary thing. The orbit is gold colored despite setting every available property to red and passing red to every available color setting method.

			driver.orbitColor = Color.red;
			orbitRenderer.SetColor(Color.red);
			orbitRenderer.nodeColor = Color.red;
			orbitRenderer.orbitColor = Color.red;
				patchRenderer.patchColor = Color.red;
				patchRenderer.nodeColor = Color.red;
				patchRenderer.SetColor(Color.red);

 

Edited by HebaruSan
Link to comment
Share on other sites

On 1/9/2021 at 7:13 PM, HebaruSan said:

The orbit still starts out corrupted, but if I re-run the whole process verbatim, it suddenly amends itself to the copy of Kerbin's orbit that I asked for. So there's some kind of mystery state that's set properly the second time but not the first; time to randomly rearrange assignments till it works...

Again for those to come after us: I had to set driver.orbit in the coroutine, after the other objects initialize themselves. Quite surprising; usually you want to properly initialize an object before passing it to other objects to use, but apparently in this case you're supposed to wait till after the end. I guess these objects only get data by reacting to events rather than grabbing it from each other proactively, and presumably they set that up in their Start methods.

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...