Spawning prefabs and location based game
Hi!
I am developing a location based game in which I spawned some prefabs on the map. I use the SpawnOnMap script to do this, but the prefab always spawns at player's position instead of using the latitude and longitude. Also, the prefabs move all the time as the player moves instead of being still at their position. I attach a snapshot from the mobile phone. and the configuration of the map.
Am I doing something wrong? How can I solve this problem?
Thank you a lot for your time.
Note: If this is a bug or support ticket, please provide the following information:
- Unity version: 2018.3.11f1
- Scripting Runtime Version: .NET 4.x
- Scripting Backend: Mono
- Api Compatibility Level: .NET Standard 2.0
- Mapbox SDK version: 2.0.0
- The platform you're building to: Android
- A description of what you're trying to do: Loading prefabs on the map
- Steps to recreate the bug if appropriate:
- Links to your logs are also helpful:


Hi,
I discovered why markers spawned at player position. It is because when the marker is instantiated, the map is not yet loaded, so the marker is spawned at player position.
However, I still have the other bug, where markers and other objects spawned by code move constantly according player position.
Any idea of this bug? Am I doing something wrong?
I'm no expert, but SpawnOnMap should be a child of the ArAlignedMap, that might fix your prefabs following player position
@branko88 I had a quick glance at SpawnOnMap script but couldn't see any object related code in there (like current object position/rotation etc). So I'm not sure if it should be object dependant, have you tried that out?
SpawnOnMap creates objects on scene/root level so objects shouldn't move with anything else, like player. @Miky91 are you sure object hierarchy looks good? Does your prefabs get spawned under player object by any chance? Or maybe player is stati in your app and you're moving the map?
@brnkhy I ran into problems when I placed my SpawnOnMap on an empty gameobject in hierarchy; prefabs position would not stay in place, it would offset from my movement. Still having problems (#1452), but I fixed that one.
@branko88 I'm afraid I can't tell much about device part as I never worked on device myself but positioning problems can be caused by a few different things. SpawnOnMap script repositions stuff in update so for example one thing might be update not being called. Or another one might be map might be positioned under some other object which is rotated or something. I'm not able to say much with only this data I'm afraid, trying to debug yourself might be faster/better.
It's solved, I had to use the correct placement option in the Abstract Map because using At location center option didn't work
Hi @Miky91 - sorry, how did you fix the prefab spawning on the player's position rather than on the lon/lat?
My prefab is sponing every location , not only in the correct location