new class item

Elapse 2 years ago updated 2 years ago 2


I struggle with classes in Bolt or maybe cause of the lack of my c# skills. I have created a new class with a c# script:

public class DropItem : MonoBehaviour
   public GameObject Gameobject;
   public Vector3 SpawnArea;
   public Vector3 SpawnAreaCenter;

   public DropItem(GameObject GO, Vector3 SA, Vector3 SACenter)
   Gameobject = GO;
   SpawnArea = SA;
   SpawnAreaCenter = SACenter;

Now I need to create a new DropItem in runtime. I have created a Graph-variable of type DropItem. When I leave it empty it goes null on enterplaymode, but I read somewhere that Bolt can transform this dynamically, so should be okay. The Problem is, that I cant create a "new DropItem"-node like the "new Vector3"-node and assign my Values.

What can I do about it?

Greetz Elapse

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):

yes, that is because Monobehaviour unassigned just comes back as (object)null. A reference is needed currently to maintain the type. As you noticed, once assigned it'll stick. In 2.x I believe this will change. But don't count on that one, not sure if it stretches to this as well. For now, this is normal behaviour, as it converts to the type it's given. If it's null, Bolt is reading it as null type, not Monobehaviour. If assigned, it can properly covert the type.

Make sense?

With Monobehaviour, you don't use the new keyword. If you aren't planning on putting it in an object, it shouldn't be a Monobehaviour. 

if it needs to be one and doesn't exist on the object yet, use GameObject.AddComponent. Then assign from that as the reference.

Hi there,

thats good to know, thanks. Now, how can I assaign the Value in the Variable window? I have nothing to choose from.

Maybe I tell whats the case I need it:
I want to store an Item(Gameobject) and its spawn location (2x Vector3)in a list on a sceneObject which then spawns the items. I could create 3 lists for each variable, for a workaround but meh. So the idea is, to store the data in a class item and pass this item to the list instead.