Obi Official Forum
Bug / Crash Null error in particle attachment in standalone build - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Bug / Crash Null error in particle attachment in standalone build (/thread-2516.html)



Null error in particle attachment in standalone build - mr-matt - 29-09-2020

I'm attaching an ObiParticleAttachment to my ropes at runtime by AddComponent and I then set the target (among other things). In the editor this works fine but in a standalone build I get this error:

Code:
NullReferenceException: Object reference not set to an instance of an object
  at Obi.ObiParticleAttachment.Disable (Obi.ObiParticleAttachment+AttachmentType type) [0x00001] in C:\Users\Matthew\Documents\repos\Radical-Relocation\Assets\Obi\Scripts\Common\Utils\ObiParticleAttachment.cs:337
  at Obi.ObiParticleAttachment.Bind () [0x00001] in C:\Users\Matthew\Documents\repos\Radical-Relocation\Assets\Obi\Scripts\Common\Utils\ObiParticleAttachment.cs:221
  at Obi.ObiParticleAttachment.set_target (UnityEngine.Transform value) [0x00019] in C:\Users\Matthew\Documents\repos\Radical-Relocation\Assets\Obi\Scripts\Common\Utils\ObiParticleAttachment.cs:52
  at Winglett.RR.Vehicles.DropRope+<MakeRope>d__35.MoveNext () [0x004ff] in C:\Users\Matthew\Documents\repos\Radical-Relocation\Assets\_Core\Content\Season 03\Vehicles\Scripts\Rope\DropRope.cs:157
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in <09bef5ecb05c47869e8650c7594390b8>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext:Exec()
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

I'm using the latest Obi version, Unity 2019.4.10f1, and HDRP 7.4.3.


RE: Null error in particle attachment in standalone build - mr-matt - 30-09-2020

I can now reproduce this error in the editor. If I comment out the OnValidate() function in ObiParticleAttachment.cs (not called in build) the same error occurs.


RE: Null error in particle attachment in standalone build - josemendez - 30-09-2020

(30-09-2020, 08:43 AM)mr-matt Wrote: I can now reproduce this error in the editor. If I comment out the OnValidate() function in ObiParticleAttachment.cs (not called in build) the same error occurs.

Hi there,

Could reproduce the issue. Will fix it and provide a patch asap.


RE: Null error in particle attachment in standalone build - josemendez - 30-09-2020

False alarm, I was using a different repo branch and the error was not even the same.

I'm unable to reproduce it on latest version in the store (5.6). Creating an attachment at runtime works fine both in editor (with or without OnValidate) and standalone.

I'm using this code in Update():

Code:
if (Input.GetKeyDown(KeyCode.G))
        {
            var attach = this.gameObject.AddComponent<ObiParticleAttachment>();
            attach.target = transform;
            attach.particleGroup = GetComponent<ObiRope>().blueprint.groups[0];
        }

Your error (line 337, in the Disable() method) points to this line:

Code:
if (actor.isLoaded && isBound)

The only thing that can be null here is "actor", which should never be null as the attachment requires an ObiActor component to be present in the game object.

Can you post the code you're using to add the attachment?


RE: Null error in particle attachment in standalone build - mr-matt - 30-09-2020

Fixed the issue. My rope gameobject was disabled until after the particle attachments were added. Switching the order such that Awake() was called in ObiParticleAttachment before I set the target solved this.