So, I manage to fix some things but I notice it's not easy...
For example I have a lot of references to components instead of gameObjects and that's one of the issues.
If I replace something like this:
public MyComponent comp
with
public GameObject go
MyComponent = go.getComponent<MyComponent>();
it is able to save without crashing or causing a stackoverflow.
Why doesn't ES3 handle component references gracefully?
I also have a lot of "normal" classes that aren't components and reference those in my gameObjects and other classes. It are these references that are causing issues as ES3 appears to not save them as reference but instead is always serializing the entire object so if I have:
Code: Select all
public class MyClass {
public OtherClass otherClass;
}
public class OtherClass {
public MyClass myClass;
}
This is causing ES3 to crash as it creates an infinite loop between those two instead of keeping track of a reference of those.
I either have to convert all of these classes to components and change the reference to GameObject and use the getComponent method...
A lot of work...
Any other, better solution for this?
Here's a concrete example:
In the economical aspect of my game, a planet has several companies who can write out orders. A company also has a bankAccount to receive payment. Other companies can fulfill those orders and pay so the model looks like this:
Each company also has a Container to store inventory so they can sell it.
The planet itself can also write out orders so I have created an ICompany interface for that purpose:
Planet : MonoBehavior : ICompany
- List<Company> companies
- List<Order> orders;
- BankAccount account;
- Container inventory
ICompany (interface)
getContainer();
getBankAccount();
Company : ICompany (normal class)
- List<Order> orders
- BankAccount account
- Container inventory
Order (normal class)
- Company issuer
- Company fulfiller
Transaction (normal class)
- Order order
- Company from
- Company to
BankAccount (normal class)
- List<Transaction> transactions
- Company company
This is not 100% as I implemented it but it conveys the message.
From the above, ES3 will create a recursive flow between Order and Company as they reference each other.
I could fix this by changing Company to be a MonoBehavior as well and create an empty GameObject as child of the planet to attach it to.
I would have to do the same for containers and attach them to a planet or company gameObject.
This is taking the component approach to the extreme imo and overkill.
If that's the only solution I'm probably looking at days of work to refactor all this.