I’m trying to do something that im clueless on.
How do I get it from a object to a scriptable object that can be inserted into AddComponent?
object T = Activator.CreateInstance(Type.GetType(PlanetSettings.PlanetName+"Spawn"));
m_AISpawn = PetSpawn.gameObject.AddComponent<T>();
This is as far as I have gotton with google and chsarp docs
ScriptableObject can’t be “inserted”… it’s a data blob with perks. Do you mean something else? And I’ll be honest, your code leaves me cold about your intentions. What’s it supposed to do?
I’m going to take several giant leaps here, correct me if I’m wrong:
- you want to add a component based on a string that is currently stored within a ScriptableObject. Ideally you would prefer to just AddComponent(someString); but this blog explains why you can’t, and some of the alternatives.
Again I’m guessing with little to go on. I won’t be back for a while over the season so hopefully someone else can help!
What is Activator.CreateInstance supposed to do? Why would you want to pass an instance of scriptable object instead of finding the type of component to add from the string name?
lol I have no idea man haha.
I really appreciate the reply.
Turns out I’m not needing it after all. I forgot my work around earlier makes so Im not needing to do this.
I don’t need to add that component anymore cause I moved the functions I was gonna used to a script of functions to use.
I wasn’t really liking the string idea anyways. Just seems super bad.