References broken when building for prod

Hi!

We are using Needle and react to create a visualization tool.
During dev things are looking nice and everything works, but when we a prod build we get weird errors.

One such example is a reference to a post processing volume, established in Unity, no longer refers to the active post processing profile.
We can log the value of the post processing profile, and it will show our assigned values. However if we log them before assigning to them we get undefined.

  updateFocusDistance(distance: number) {
    this.focusDistance = distance;
    const profile = this.post?.sharedProfile;
    if (!profile) return;
    for (const ef of profile!.components!) {
      if (ef instanceof DepthOfField) {
        ef.focusDistance.value = distance;
      }
    }
  }

Original Post on Discord

by user 219335701790064640

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

Hi, can you show a more complete example of what/when you log those values?

Well, I can.
But no matter where I try to log the value (calling the method I sent) I would get undefined from ef.focusDistance.

It is called from the Update method of an object in the scene (with a direct reference to a volume component)

by user 219335701790064640

Code_oRZhcxbH9e.png

by user 219335701790064640

Could you send us a bugreport with this?

Yes, I can.

But is there any known issue regarding react, next and needle? We are experiencing several issues.

(I will send a bug report, but just in case)

by user 219335701790064640

Did you report those issues before?

No

But I know someone from my team reported a similar one (double reference when using finComponentByType)

by user 219335701790064640

Ah you mean him? I dont think we got any bugreport Discord

@SteffenMFureli updating the focus distance works for me. All i did was applying a sin function to the value (and uncommenting the line that wrote to value) - so the effect is updated when you change it - I didnt change anything else ef.focusDistance.value = Math.sin(this.context.time.time * 3) * 3 + 3;
Capto_Capture_2024-01-30_11-34-25_PM.mov

The dist value you pass in is 1 - when i’m trying to visualize that in the scene it looks like this:


Yes, I think thats him.

Well, to be more precise:
Everything works when deployed in our development environment, but when running a prod build it somehow fails. Could there be specifics in how we have set up our dev env that could cause the issue?

Is it possible to perhaps have a one to one someday where I can show you how it is setup?

by user 219335701790064640

Sent you DM

Hi @SteffenMFureli - the issue seems to be caused by webpack’s chunking which causes issues where types existing multiple times in production builds. Until there’s a better solution one way to make nextjs builds work again right now is by adding these two lines to the webpack config:

config.optimization.concatenateModules = false;
config.output.pathinfo = 'verbose';

We’ll look further into providing a better solution tho - I just wanted to give you a quick update

I tried this, but very little happened.

My “FireplaceController” reference made in Unity still gets broken and returns undefined.
And when using “FindObjectOfType” I get one of my cameras in return.

by user 219335701790064640

This arr returns three objects, a camera, a random environment controller and lastly my desired FireplaceController

by user 219335701790064640

Have you tried deleting the nextjs cache? Could you share your next config here again?

Can you also try removing needle engine from the transpiled packages list? After
nextconfig.transpilePackages.splice(nextconfig.transpilePackages.indexOf('@needle-tools/engine'), 1);

like this