Jump to content

ResearchAndDevelopment Initialization


Recommended Posts

Hey all you Science lovers out there.

I'm working on my custom biome loader, and I can't seem to get the ScienceDefs.cfg to load up new results for my biomes. I'm assuming it's because the biomes are being loaded after the config file is, and they are stripping out unused biomes on load. So I figured I would just inject them at runtime like the biomes. I have gotten it to mostly work, except that I have to visit the research lab scene first, or I throw an ArgumentException: An element with the same key already exists in the dictionary. Does anyone know how to initialize R&D without visiting the scene? Everything in the class seems to be static, but I can't call anything that looks initialization. Any thoughts?

Link to comment
Share on other sites

I think ResearchAndDevelopment gets initialized when reaching the SpaceCenter after it detects that there are no researched Tech Nodes (presumably it unlocks the start node when it initializes). Depending on how your injection works, I would suggest loading the biomes on the Flight scene or sometime after the player visits the Space Center the first time. As for your actual question, ResearchAndDevelopment appears to have an Initialize function, but I'm not sure where the arguement for it's initialization comes from.

Link to comment
Share on other sites

It doesn't get initialized when reaching the space center, or even in the flight scene. I was loading the biomes in the flight scene, and couldn't even loop through the experiment IDs. But if I go to the science center then the flight scene, it worked fine. Yeah, I see ResearchAndDevelopment.Instantiate(UnityEngine.Object original) too. Does anyone know what "original" would be?

Link to comment
Share on other sites

It might be possible to inject the Results without going through RnD. When I was working in my plugin, I manually changed the ModuleScienceExperiment's ScienceExperiment (ModuleScienceExperiment.experiment variable), which unintentionally (for me) changed the version RnD uses when determining stuff so that it applies to all experiments with that ScienceExperiment (and not just that specific part module). I believe you can change/add to the Results dictionary for each experiment through that, if you've already gotten the actual Biome determination to work.

Link to comment
Share on other sites

Does anyone know how to initialize R&D without visiting the scene? Everything in the class seems to be static, but I can't call anything that looks initialization. Any thoughts?

You might simply be trying too early. I just had a similar problem: I wanted use ResearchAndDevelopment.GetScience() in a MonoBehavior's start function during flight, but it returned null (likely because RnD.Instance didn't exist). Creating a coroutine that waited for RnD.Instance to exist solved the problem for me.

Link to comment
Share on other sites

It might be too late for results at that point (for the first flight anyways). Here is a general workflow of what happens with Science Data from what I have seen:

1) ScienceExperiments are presumably loaded in sometime during the big loading process (without RnD)

2) When ModuleScienceExperiment part modules are loaded in the flight scene, they obtain a copy of the ScienceExperiment (from RnD? RnD and when MSE gets its experiment occur at roughly the same time window I think)

3) When DeployExperiment is called on the experiment, the ScienceData that is made by the Window that pops up uses the values (and more importantly, the Results) from the stored ScienceExperiment. Additionally, it's the experiment values that help determine whether the experiment can be done in the first place

Basically ResearchAndDevelopment is left out of most of the process towards getting the Results to the user. The only time RnD might have any impact on the Results used for the first flight would be very shortly after its initialization when the experiment is loaded into the module. All other times before the ScienceData is submitted to RnD uses the module's ScienceExperiment itself (which, if modified, changes the ScienceExperiment that RnD returns).

Now that I think about it, you could probably just iterate through ResearchAndDevelopment.GetExperiment("experimentID") which I think is static and modify the experiments there

Link to comment
Share on other sites

It might be possible to inject the Results without going through RnD. When I was working in my plugin, I manually changed the ModuleScienceExperiment's ScienceExperiment (ModuleScienceExperiment.experiment variable), which unintentionally (for me) changed the version RnD uses when determining stuff so that it applies to all experiments with that ScienceExperiment (and not just that specific part module). I believe you can change/add to the Results dictionary for each experiment through that, if you've already gotten the actual Biome determination to work.

I'm not really trying to do anything with the partmodules, though I suppose its a possibility if it comes down to it.

xEvilReeperx, I'll look into trying something like that. Thanks for the idea.

Link to comment
Share on other sites

Try iterating through all of the ScienceExperiments that you can get from ResearchAndDevelopment.GetExperiment(experimentID) when the player visits the Space Center the first time. I suspect injection there will work without going through partmodules.

Link to comment
Share on other sites

That's where I was trying to do it, but for some reason it seems to load after my plugin. Using evilreeper's suggestion, I did manage to get it to load correctly in the flight scene. I may have broken my thermometer doing it, but at least the R&D part was solved...

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