Will Not Fix

GetOrAddGeneratedComponent only works sometimes.

CaptainTuna 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 1

I have a very simple monobehaviour script that is calling gameObject.GetOrAddGeneratedComponent<TestClass>();

The issue is that, when I run the project, a Bolt Component is created on the same gameobject to which the monobehaviour script was attached, BUT with no class linked to it.

In some cases I managed to make it work by calling that same method twice, but this only worked sometimes and I wasn't able to get a consistent repro for when it did work.

Bolt Version:
Bolt v.2.0.0a10
Unity Version:
Windows 10
Scripting Backend:
.NET Version (API Compatibility Level):
.NET Standard 2.0
Bolt 2
Will Not Fix

Hi CaptainTuna,

Sorry for the late reply and thanks for the report.

That method is not part of the supported API and should not be publicly exposed to users. It is meant for internal use only. I'll look into hiding it better in future releases.

You should be using GetOrAddBoltComponent instead, which passes a BoltClass asset as a parameter.

I'll close this for now, but feel free to comment again if ever the alternative doesn't work either in your case. If so, please provide reproduction steps.