react-native-unity icon indicating copy to clipboard operation
react-native-unity copied to clipboard

The specified child already has a parent. You must call removeView() on the child's parent first.

Open Agreafel opened this issue 2 years ago • 0 comments

I am having a similar issue on a project currently. I have found that it is possible we may need to set the view settings of the unity player to not attach to root, according to this stack overflow thread: https://stackoverflow.com/questions/28071349/the-specified-child-already-has-a-parent-you-must-call-removeview-on-the-chil The suggested fix of removing the view from the parent seems to be applied on the ReactNativeUnity.java script as

        if (unityPlayer.getParent() != null) {
            ((ViewGroup) unityPlayer.getParent()).removeView(unityPlayer);
        }

but i still get the error at line 135 of the previously mentioned script where

group.addView(unityPlayer, 0, layoutParams);

would it be possible to apply the attachtoroot=false solution to the unity player in some way? Or if that is not the correct solution to this pattern, is their an alternate issue with android view parents that can be applied here so the android mount is more stable while navigating throughout an app?

Originally posted by @Agreafel in https://github.com/azesmway/react-native-unity/issues/44#issuecomment-1409499991

Agreafel avatar Jan 30 '23 23:01 Agreafel