cakeslice / Outline-Effect

Outline Image Effect for Unity
MIT License
1.48k stars 201 forks source link

Not working on prefabs #54

Closed cevanno closed 3 years ago

cevanno commented 3 years ago

Just downloaded this and have run into a (hopefully) noob issue. I put the Outline script on a simple cube (with OutlineEffect on Main Camera) and it works. Can toggle the effect easily. Then I put the Outline script on the same cube as a prefab that is instantiated at runtime and in its construction process (when Instantiate() is called) I get this unhandled exception: NullReferenceException: Object reference not set to an instance of an object cakeslice.OutlineEffect.OnPreRender () (at Assets/OutlineEffect/OutlineEffect/OutlineEffect.cs:228)

I assume this is a timing or order of construction issue because that line of code accesses objects created by the component. Any suggestions?

cakeslice commented 3 years ago

Can you send me a simple scene that reproduces the issue?

I will take a look

Note: Just the scripts, the scene and the prefab

cevanno commented 3 years ago

sure. Not sure best way to send privately so posting here. This small project lets you click mouse on the cube in the scene to place an object at the hit point. You will see the new object instantiated in the Hierarchy. This works as is. But the Outliner component is disabled on the Marker prefab (sorry, for clarity I thought changing the instantiated object to this marker was easier to get the point across). Stop the play and enable the Outliner component on the Marker prefab and run again. You will see the error. SurfaceLineMaker-stdpipe.zip

cakeslice commented 3 years ago

Ok so the reason why it's crashing and it won't work is because you don't have a MeshFilter component on the one you're trying to use the outline.

The outline will not show if there is no object being rendered.

In your case you need to add the Outline component to the "Marco" or "Vidrio" objects instead of "Marker"

cevanno commented 3 years ago

Wow thanks. This error doesn't seem too noob crazy for a user so a try catch when you get the meshfilter would give the opportunity to report the error in a log and assist integrators.

cakeslice commented 3 years ago

The problem is that you don't need a MeshFilter in some cases like for adding an Outline to a SpriteRenderer so I can't throw an error if there is no MeshFilter.

But I added a check and it doesn't crash anymore in the latest commit :)