Questions tagged [monobehaviour]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
26 views

Unity Thought There Was No MonoDevelop In Scripts in My Code

Weird Unity thinks that the code that I've checked already has a MonoDevelop inside of it, but unity doesn't think so, can you help find what I wrote wrong in these two scripts? ...
INDO_GEMENG's user avatar
-1 votes
1 answer
32 views

MonoBehaviour Wouldn't Work [duplicate]

I was writing the character controller for my player character, but Unity said that there was no mono behavior script in the file I'd written the file right and I included the mono behavior ...
INDO_GEMENG's user avatar
0 votes
2 answers
88 views

Initializing Monobehaviour in Unity

I have three scritps and one plain C# class. EnemyMonobehaviour, EnemyAttackMonobehaviour and UnitState plain class. In enemyMono I have Initialize function that initializes unitState. ...
Taras Fityo's user avatar
0 votes
1 answer
61 views

Pattern for scripts that should only update when in trigger range

I have a script that triggers when the enemies are in range of my objective, but it also contains an Update method for its the damage. I noticed that Update is being called even when the enemies are ...
Doug Ray's user avatar
  • 143
0 votes
1 answer
2k views

Gameobject does not derive from MonoBehaviour

I am trying to put a gameobject into a prefab. Unity says "You are trying to save a Prefab that contains the script 'NPCDebugInfo', which does not derive from MonoBehaviour. This is not allowed. ...
tmighty's user avatar
  • 869
1 vote
1 answer
189 views

How to connect the Data Layer (Models) with the Visual/Interactive Layer (MonoBehaviours)?

I have been struggling with this dilemma for quite a while already. Our game is complex enough that we have tons of logic in normal C# scripts that function very independently of any Unity specific ...
fguillen's user avatar
  • 223
0 votes
0 answers
121 views

How to create same paradigm of monobehaviour and processing in C++

Having worked with monobehaviour and processing before, is it possible to create the same paradigm both frameworks use which basically is writing all code in two main functions, start/setup and update/...
Fudge Racoon's user avatar
0 votes
1 answer
682 views

Two Colliders on the same GameObject for different purposes

I'm somewhat new to Unity and am trying to build a battle system. Right now, I have an attack that checks collisions with enemy objects like this: ...
G_hi3's user avatar
  • 111
0 votes
1 answer
287 views

How to call StartCourotine in abstract class?

Bellow is my code. I have an abstract class and a inheriting class. This keeps giving me an NullReferenceException, on the ...
ManoTech's user avatar
  • 145
2 votes
1 answer
503 views

How to subscribe for events for easy unit testing?

I've run into the same problem multiple times that is begging for a solution. I try to write a lot of decoupled code to make my MonoBehaviour scripts as reusable as possible. This means that I end up ...
Adam B's user avatar
  • 735
0 votes
0 answers
640 views

Unity - Which is more optimal persisting between scenes? `DontDestroyOnLoad` or `LoadSceneMode.Additive` [duplicate]

User philip previously marked this as a duplicate question of this, but failed to actually read either question it seems. The question that this was marked as a duplicate of, does not address the ...
Dan_'s user avatar
  • 101
1 vote
1 answer
1k views

How to reference nameof private serialized field in unity custom inspector

I'm running into a problem that I think will seriously affect maintainability down the road, so I'd like to figure it out now before it becomes a problem. I've been starting to use private [...
Adam B's user avatar
  • 735
-1 votes
1 answer
41 views

Public MonoBehavior string fields empty

This is bizarre enough that it has to be me being an idiot. I have a MonoBehaviour with some public fields and public methods: ...
BanksySan's user avatar
  • 200
1 vote
1 answer
144 views

Unity, WaitUntil in a self-made message box class

I managed to make a simple message box prefab with a Text and a Button through Canvas, and ...
PiggyChu001's user avatar
-1 votes
1 answer
300 views

How do I convert an interface into a MonoBehavior in Unity?

In my method iTest.doStuff(), I try to convert interface testInterf _ti into a MonoBehavior. This gives me "error CS0246: The type or namespace name 'MonoBehavior' could not be found", but in the ...
Tom Titanium Lento's user avatar
1 vote
0 answers
18 views

Unity, weird error appearing after playing in editor

got a bit of a weird error, hopefully someone here can help. So I have created a custom class (does not derive from Monobehavior). Then I have a variable for the class, in the Start() method I set ...
John Smith's user avatar
  • 1,235
0 votes
1 answer
613 views

Is it efficient to have a only-data MonoBehaviours on lots of game objects?

I'm working on a voxel based game and this solution would make the implementation of networking and other features a lot more easier, it is less error-prone, easier to edit in the Editor, etc. So the ...
Tudvari's user avatar
  • 701
0 votes
3 answers
62 views

Public value null after assigning it from a different script

Hello I am a beginner in Unity and still currently exploring with scripts. So I ran into a problem. In FetchAndAssign.cs Script ...
Addy Pete's user avatar
1 vote
1 answer
2k views

Waiting for object's Awake() after loading a new scene synchronously

I have a GameScene with an initially active GameObject in it, which has a singleton component: ...
Jacob's user avatar
  • 2,522
8 votes
1 answer
4k views

Unity Hybrid ECS with "old way"

Is it possible to use Hybrid ECS with some components and the standard MonoBehaviour with all your old code? I want to know because I already have some game ...
Marc Rasmussen's user avatar
-1 votes
1 answer
179 views

Unity3D MonoBehaviour in .dll loses serialized data when dll is updated

I have a MonoBehaviour class in a compiled DLL that I have included in my Unity project. It automatically serializes public field data as expected. However, whenever I update the dll (by overwriting ...
GorillaOne's user avatar
0 votes
0 answers
101 views

Capture Video without Third Party SDK's

I am trying to capture the game play and store it on local memory without using any third party sdk's. I tried This Video Capture Script but i didn't get the recorded file even i don't know whether it'...
Manoj Balaji M's user avatar
0 votes
1 answer
151 views

few button image are not updating

I am working on a game that contain 1000+ buttons starts from 0 - 999 with 3 decimals like 0-9, 00-99 and 000-999. if the user click the button the button image want to change. it working fine for me ...
Manoj Balaji M's user avatar
0 votes
0 answers
270 views

Best practice to define fields scope in C# script of Unity in regard to serialization?

I know from Object Oriented Design perspective that in order to provide encapsulation, we should avoid defining ...
Emad's user avatar
  • 1,126
2 votes
2 answers
3k views

How can I give a MonoBehaviour field a default value that depends on the object?

In Unity3D, I have a MonoBehaviour which gets added to game objects. I'm adding a string "name" field to it. I'd like the ...
Dan Hulme's user avatar
  • 187
0 votes
2 answers
8k views

How to make Lists (and Arrays) in Unity only take GameObjects of a certain "type"

If I were coding in generic C# I can create a list that only stores a certain type of object. If I accidentally try to add anything other than that type to the list I will be promptly told and can fix ...
Francis's user avatar
  • 149
1 vote
1 answer
665 views

StartCoroutine from other MonoBehaviour is not working

I am trying to replicate the model of Unity documentation about coroutines, but I want to partition it in another class: I have these two: ...
JamesB's user avatar
  • 277
1 vote
1 answer
1k views

What is the difference between a game object being disabled and it made inactive?

I am looking over a script that has a particular function called to disable the script and mark a list for re-structuring: ...
Gnemlock's user avatar
  • 5,233
0 votes
1 answer
228 views

Have several classes with a common interface, but still able to access MonoBehaviour methods through that interface?

In our project we used to have a PlayerObject class and then Unit and Building derived from that class. We recently started taking a look at Bolt, which requires classes that define objects that may ...
Douglas Gaskell's user avatar