Think of each unique Scene file as a unique level. See in Glossary of the Scene A Scene contains the environments and menus of your game. To access the Camera settings menu, click the Camera icon in the toolbar A row of buttons and basic controls at the top of the Unity Editor that allows you to interact with the Editor in various ways (e.g. A GameObject’s functionality is defined by the Components attached to it. These adjustments do not affect the settings on GameObjects The fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. See in Glossary settings menu contains options for configuring the Scene view An interactive view into the world you are creating. The output is either drawn to the screen or captured as a texture. To access the list call DemoScriptable.The Camera A component which creates an image of a particular viewpoint in your scene. If (DemoScriptableHashCodes.Contains(guid)) check guid to avoid complex comparison If (!DemoScriptableHashCodes.Contains(guid)) can be HashCode, but this is not guaranteed to be unique. Public static List DemoScriptableHashCodes = new List() Public static List DemoScriptables = new List() This can also be a dictionary, but this way you have list and can run a for or foreach loop. Public class DemoScriptable : ScriptableObject Add this method to any class to see the log print when the game starts.ĭebug.Log("The game has started and this class is Initialized") Īs pointed out by derHugo: The attribute initializes the class itself so it would not work as a way to add instances to a listĪnother possible other solution: If you want to avoid Resource.LoadAll would be to do something like: using System The code for that would look something like this: // The name of the method does not matter. (The script does not need to be in the scene) If you really want to call a method on a ScriptableObject when the game starts, consider using the attribute - Allow a runtime class method to be initialized when a game is loaded at runtime without action from the user. Instead of having the scriptable objects add themselfs, consider having the factory call Resources.LoadAll this will load all the objects of type T in your project. How can I use OnEnable on ScriptableObjects to populate my factory with the types it will dispense? Instance = /*SomeRandomGameObject*/.AddComponent() public static MonoBehaviourFactory Instance But the issue with that approach is that the instance of the MonoBehaviourFactory would not have the references dropped in from the inspector such as someInspectorText. I don't know of a good way of instantiating the factory pre-awake, I thought about using something like the following. Script execution order does not improve the situation. In it's awake have something like: var thingTypes = Assembly.GetAssembly(typeof(ThingType)).GetTypes().Where(thingType => thingType.IsClass & !thingType.IsAbstract & thingType.IsSubclassOf(typeof(ThingType))) īut now I'm stuck - I have the classes for ThingTypes, like, ThingAType but not the individual SOs.Īnd an additional problem, is that OnEnable is called before my factory's Awake, so it is not initialized yet. The second approach is to have the factory be a MonoBehaviour, and do reflection magic. I don't understand this exception, it makes sense to me that if OnEnable is called before the scene loads, and then the SO is destroyed at scene load. (Did you spawn new GameObjects from OnDestroy?) Some objects were not cleaned up when closing the scene. The third problem is that I'm receiving this exception: The second problem is that OnEnable is called only when the scene has a MonoBehaviour referencing that ScriptableObject asset which isn't always the case.Įven now when I'm reproducing the behaviour in a small project I can't put my finger on the exact requirements for OnEnable to be called. The first is that OnEnable is called from the editor, I've gotten around that with the if UNITY_EDITOR. Public abstract class ThingType: ScriptableObjectĭebug.Log("Enabling ThingType of type: " + this.name) NewThing.GetComponent().sprite = thingType.sprite NewThing.GetComponentInChildren().text = thingType.name GameObject newThing = MonoBehaviour.Instantiate(thingType.prefab, ) Public void RegisterThing(ThingType thingType) Private static ThingFactory instance = null I've explored two approaches, one is having the factory not be a MonoBehaviour: So ideally something like each SO registering itself in the factory on it's awake would be great. I'd like to not need to append to the Factory each new SO that I create. My factory creates instances based off ScriptableObject's ("SO") properties.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |