- Home /
Question by
AudiOishi · Dec 14, 2010 at 02:48 PM ·
scriptableobjectinheritanceconstructor
How do I use CreateInstance with a non-default constructor in C#
How can I use CreateInstance with custom constructors:
using UnityEngine; using System.Collections;
public class Example : ScriptableObject { // don't allow a call to the default constructor private Example () {}
// how do I use CreateInstance to create an instance of // Example that calls this constructor public Example (string message) { Debug.Log ("It worked!! " + message); } }
Are there any examples of this anywhere?
Comment
Best Answer
Answer by Mike 3 · Dec 14, 2010 at 03:57 PM
You can't, but you can add in an init function which you can call after CreateInstance (and can be called from the constructor(s) with the parameters to keep the code sane)