#archived-code-advanced

1 messages ยท Page 181 of 1

undone coral
#

think critically about whether this makes sense

#

put a .tsv file on a public url

#

export occasionally from google sheets

#

don't create an integration with google sheets

shell jasper
#

Hi, if I do

readRequest = AsyncGPUReadback.RequestIntoNativeArray(...);```
am I guaranteed to have the async readback begin after compute shader has completed or should I double buffer?
sly grove
devout orbit
#
  "ConnectionStrings": {
    "Default": "Server=localhost;Database=credentials;Uid=root;Pwd=xnxx!;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}```
Anyone any suggestions on why I can't connect to mysql server it is running :/
#

Using .net core

shell jasper
# sly grove you are not guaranteed, apparently. I believe you would need to use a Graphics F...

Thanks! I tried implementing that using two command buffers, one as AsyncCompute and the other one as a normal command buffer. I dispatch them using Graphics.ExecuteCommandBufferAsync and Graphics.ExecuteCommandBuffer respectively. Now I'm getting AsyncGPUReadback - NativeArray does not have read/write access and AsyncGPUReadback - NativeArray should not be undisposable while trying to read back from the computeBuffer. If I understand correctly, CommandBuffer.RequestAsyncReadbackIntoNativeArray(...) wants to deallocate the array, hinting that it expects to output to a temporary. I'm not really keen on copying the entire array to avoid this, is there a way to avoid this behaviour? I tried requesting readback and getting the data from the request itself, then copying, but it performs terribly.

Relevant code:


cBufCompute = new CommandBuffer();
cBufCompute.SetExecutionFlags(CommandBufferExecutionFlags.AsyncCompute);
cBufCompute.DispatchCompute(computeSph, ...);
cBufFenceDone = cBufCompute.CreateAsyncGraphicsFence();

cBufReadback = new CommandBuffer();
cBufReadback.WaitOnAsyncGraphicsFence(cBufFenceDone);
cBufReadback.RequestAsyncReadbackIntoNativeArray(ref particles, bufSimData, (AsyncGPUReadbackRequest r) =>
{
   ...
});```

Edit: Trying to output to a NativeArray with temp allocator results in a hard crash of unity editor
undone coral
undone coral
#

looks like a particle simulation?

#

async readback request returns a callback but it isn't complete when the callback is called

#

i know right?

#

so you might be doing the dispose at the wrong time

#

or whatever

#

why would request async readback into native array want to deallocate it?

#

that's weird

#

i'm not sure if you can take ownership of the data from the callback

#

you should be able to do

#

if you can't file a bug because that's horrible

#

(take ownership i.e. std::move)

#

ref particles should already be what it std::moves into

shell jasper
# undone coral looks like a particle simulation?

Yes. Let me explain what I'm trying to do to avoid XY problem ๐Ÿ˜‰
Basically I'm trying to offload some computations to GPU using compute shaders.
The idea is to schedule GPU work on fixed update (before physics) and start a coroutine that waits for end of physics update. Then post-physics read the data back on the CPU side and do some "merging". The optimization here is to avoid waiting for the CPU to be done with physics and start downloading the data right after compute shader is done.

My mistake in the code above was that I scheduled the work multiple times before it was completed, that's why Graphics.ExecuteCommandBuffer was crying - I was trying to double-write to the same array. That was fixed by putting guard booleans to see where exactly I am in the execution pipeline, turns out that the work is scheduled properly, but I'm not able to get the data the same frame - best case it's available next frame

undone coral
#

i see

#

i'm not sure why it would be tied to a particular frame

#

but it makes sense to me that only one async readback request can be in flight for the given array at a time

#

since it probably std::moves it (or whatever - takes ownership)

#

until the request is done

shell jasper
#

Yeah, this does sound correct

undone coral
#

anyway

#

i think you want this

#

this readback pool

shell jasper
#

I will look into it in a moment, thanks ๐Ÿ™‚

#

I assumed that calling request.WaitForCompletion would work immediately after the command buffer is executed, but that doesn't seem to be the case

undone coral
#

then you can have multiple readbacks in flight idiomatically

undone coral
#

do you observe the callback being called without data?

#

i believe if you do, which was my memory of how this worked, then it's like it's "ready to begin"

#

but not "done"

#

if that makes sense

shell jasper
#

I am sure that the request might not be created yet when the command buffer is executed, the request seems to always have a data ptr. Let me check if it's done

#

Ok - when the callback is called from cBufReadback.RequestAsyncReadbackIntoNativeArray it's always done.

#

however, I have no way to actually wait for that data to be ready from the main thread as I don't get any reference to the request itself when scheduling the command buffer

undone coral
#

when it started

#

hmm

#

well you can definitely pass something into the closure

#

and use that in the pool

#

i think do the thing keijiro does at minimum

#

since he knows what he's doing

shell jasper
#

that's what I thought after noticing that it was scheduled multiple times (with the array access errors)

undone coral
#

it's tough for me because i haven't used this API in a while

#

rent a native array from the pool

#

return it when it's done

#

use the pool

#

you can have multiple readbacks in flight

#

that's totally sensible

shell jasper
#

AsyncGPUReadback.WaitAllRequests(); seems to be able to wait for everything properly - let me double check that

undone coral
#

yes but it might take longer than 1 frame

#

which you don't want to do anyway

shell jasper
undone coral
#

i think you want to get every frame right?

#

hmm

#

but what if it's not done in a frame

shell jasper
#

stall

undone coral
#

stall what?

#

the render thread?

shell jasper
#

Stall main thread, don't go into next frame until the data is back

undone coral
#

unity doesn't like that

#

VintageUnity ๐Ÿšซ

shell jasper
#

Well, I need the game thread to wait for the GPU to be done with computation and transferring the data

#

it's render thread that actually performs the download afaik

#

at least that's what the profiler says lol

undone coral
#

hmm

#

why use async readback then?

#

don't you want... sync readback or whatever?

shell jasper
#

Because I can start it as soon as compute is done

undone coral
#

yes but that doesn't give you anything

shell jasper
#

hmm, I'm not sure I follow what you mean

#

If I can schedule the download right after compute is done, it should not take cpu time from game thread (which is doing physics at the time), but rather use render thread to fill my native array in parallel

undone coral
#

what you are saying sounds right to me

shell jasper
#

because at that moment gpu is not very busy, neither is render thread

undone coral
#

but it sounds like it's possible that the gpu doesn't finish its thing in time

#

if you'd like to block the main thread

#

i suppose use a semaphore and don't overthink it

#

i'm sure there's a better way though

shell jasper
#

well, tried it, editor freezes.

#

I suppose main thread needs to kick-off the rendering pipeline before I want to stall it

#

ugh

undone coral
#

that would suggest the

#

yes

#

but in my experience the command buffers can be send synchronously

shell jasper
#

The computation, yes, the download - apparently not.

undone coral
#

and if you break in e.g. unity plugin C++ code it will have all the mono shit in the stack

shell jasper
#

ughh I wanted to avoid going native, that was the whole point of using Unity in the first place

#

lol it was supposed to work as lightweight rendering and system abstraction for me

#

now it feels like I'm going against the wind trying to schedule crap properly

#

instead of doing the actual simulation lol

#

release the source already, I would debug it on my own...

undone coral
#

okay well

#

it should say when command buffers get sent

#

and when you can wait for this semaphore

#

in this doc

#

in that player loop doc

shell jasper
#

AsyncGPUReadback.WaitAllRequests(); does the job - which means that if I could get a reference to the request before it's done I would have it solved

#

Idk if I want to do that tho, statics bad

undone coral
#

okay so help me understand why you need the reference to the request?

#

you could pass an object into the closure of the callback

#

that you modify when it's called

shell jasper
#

but it's called when the request is already done

#

which might be too late

undone coral
#

i.e.

var myToken = new object();
cBufReadback.RequestAsyncReadbackIntoNativeArray(ref particles, bufSimData, (AsyncGPUReadbackRequest r) =>
{
   DoSomethingTo(myToken);
});
...
whatever it is you needed
shell jasper
#

you mean the RequestAsyncReadbackIntoNativeArray callback

undone coral
#

yes

shell jasper
#

it's called when the request is done

#

r.done == true

undone coral
#

what else do you need from it?

#

because the data will be in the particles

shell jasper
#

if I got it the moment I execute the command buffer I could r.WaitForComplete()

undone coral
#

i see what you mean

shell jasper
#

from the PostFixedUpdate

undone coral
#

okay

#

well you can spin wait a tiny bit

#

but my suspicion is that it will never start until you have exited mono player loop crap

shell jasper
#

I can't, because it doesn't kick off the work on the other threads

undone coral
#

which is why your semaphore doesn't work

tacit sonnet
#

Is there a way to keep an GUI object always on screen. Like a dialogue being spoken by someone offscreen which you still can see.

undone coral
#

yeah

shell jasper
#

I suspect* it doesn't kick off work on other threads

undone coral
#

so you're a little boned here

#

i guess we have only our suspicions lol

#

you're close

shell jasper
#

presumably, waiting for a request flushed the commands

shell jasper
tacit sonnet
#

Is there a way to keep an GUI object always on screen. Like a dialogue being spoken by someone offscreen which you still can see.
Camera.main.WorldToScreenPoint / or view port
Works, but when your object is more then like 70-80 degree off screen from camera, dialogue box slide off on Y coordinate.

shell jasper
tacit sonnet
#

Object is to the right

#

But after enough angle is given it just slide down.

shell jasper
#

@undone coral thanks for the help, I will try to decompile this crap, maybe there is an internal that flushes the render commands or something like that, hopefully

tacit sonnet
shell jasper
tacit sonnet
#

Telling someone, "just do the math yourself" means virtually nothing ๐Ÿคฃ

#

Thx i'll look into the link you provided.

shell jasper
#

"Is there a way to keep an GUI object always on screen. Like a dialogue being spoken by someone offscreen which you still can see." - question is too broad to give any more precise answers, sorry. I'm not sure which part of "doing math" might be difficult if I don't know what is your expected result

tacit sonnet
#

Expected result is that an dialogue object should stay on screen relative to position of the speaker.

#

When he is offscreen it should be in diurection where he is offscreen

shell jasper
#

"project it to a screen plane" was my first response. You might need to normalize it to screen border in case it's behind. dot product will tell you if something is in front or behind

chrome forge
#

i was messing around with the versions to try them is their any way to see the original version of my game

quartz stratus
#

Does anyone have a guess as to how Time.time works under the hood? Like, what's Unity doing on the C++ side?

gray pulsar
wooden cedar
final steeple
#

Unity ships with PDB files so you can inspect the implementations in a disassembler if you're really that curious

#

Not all versions of the engine ship with untrimmed PDB files though, so the quality of the output you get can vary

#

I don't think Time.time in particular does anything special though, it just returns a value that is calculated elsewhere in the main loop

#

Yeah, looks like the C++ implementation is basically just return GetTimeManager()->m_ActiveTime.m_CurFrameTime;

#

In theory though, you could do FindObjectOfType(Type.GetType("UnityEditor.TimeManager, UnityEditor")) to get the instance

#

From there you could probably use SerializedObject or EditorJsonUtility to read the time field

#

but... why would you even bother ๐Ÿ˜„

quartz stratus
#

Thanks everyone. Lots of great stuff.

#

I was investigating an Android/Fire OS crash and was wondering if Time.time had any weird compatibility concerns that I wasn't aware of. But of course it turned out to be a memory issue in the end lol.

rigid dagger
#

Hey guys ! I have some weird stuff happening with WebGL PersistentDataPath. I can write files here, but when I want to use a UnityWebRequest to get my file back the URL is automaticaly reworked by the UnityWebRequest that make it bad. Instead of something that should be like this to access IndexedDB :

/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3
this will automaticaly become this everytime :
https://mywebsite.com/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3
and I get a 404 because of that.
Do you know how to fix this ?

fleet lion
rigid dagger
#

So I know that the file is the right place, something like "/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3"

fleet lion
#

what is the url of the web request?

#

the wrong one I mean

rigid dagger
fleet lion
#

Im not familiar with unity web requests specifically but I am with general API's, etc.

#

aah i see

#

and what is the format of the url that you are expecting to receive?

rigid dagger
#

if the input URL starts with a single slash (/), then the system assumes the inout is a path relative to the current domain on which the Unity application is running. On non-WebGL platforms, the system will prepend http://localhost to the URL.

On WebGL, the system will prepend the scheme and host of the path by which the Unity WebGL application is being accessed. For example, if the Unity WebGL app is being accessed via https://unity3d.com/myapp, then the system will prepend https://unity3d.com to relative paths.

#

but I really need only this to access the file for the URL :

/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3

fleet lion
#

aah I see

rigid dagger
#

that's why UnityWebRequest seems to not work with any kind of assets in persistentDataPath

#

because this will always change the URL to a bad one, assuming it's a relative path but it's not

fleet lion
#

I see, that makes sense

rigid dagger
#

if only there is a way to tell UnityWebRequest not to rework the URL

#

or maybe a way to change the URL a little to prevent the rework but still going at the right place

fleet lion
#

Cant you just use a regular C# http library?

#

I would think you could achieve the same thing making a 'regular' http request right?

rigid dagger
#

@fleet lion well this will not read my MP3 as an AudioClip if I try that I think ^^

#

at best this will get the binary data of the file

fleet lion
#

Can't you retrieve the data and parse it yourself?

rigid dagger
#

and I can already do that with System.IO.File

fleet lion
#

aah orright

rigid dagger
#

well, it's a possibility

fleet lion
#

Im afraid I cant help any more with this then, my knowledge about Unity's web requests really isnt in depth enough, sorry about that!

rigid dagger
#

no problem, thank you ^^

#

there is some examples of the web to get an AudioClip from binary data of the file, but this seems not really stable, that's why I will do it only if I can't find a working solution with UnityWebRequest

final steeple
#

@rigid dagger Can't you just transform the URI into an absolute URI?

rigid dagger
#

@final steeple that would be perfect but I don't know how to get that for a file in the indexedDB

final steeple
#

does file:///idbfs/... not work?

#

@rigid dagger

var builder = new UriBuilder
{
    Scheme = Uri.UriSchemeFile,
    Path   = "/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3"
};

using var www = UnityWebRequestMultimedia.GetAudioClip(builder.Uri, AudioType.MPEG);
yield return www;
var clip = DownloadHandlerAudioClip.GetContent(www);

this should work

quiet bolt
#

using var?

#

wait how exactly does using work outside of namespaces

novel plinth
#

using there is IDisposable

final steeple
#

Yeah, that's not a namespace import

quiet bolt
#

yes ik, hence outside of namespaces

sly grove
#

It just cleans the thing up properly

quiet bolt
#

ahhh

final steeple
#

using var x = something; is equivalent to

#
{
    var x = something;
    try
    {
        // ...
    }
    finally
    {
        x.Dispose();
    }
}
sly grove
#

Try - With - Resources from Java if you're familiar with that

final steeple
#

(roughly)

quiet bolt
quiet bolt
#

i never really bothered with disposing and what not so that explains why all of this is so new to me ยฏ_(ใƒ„)_/ยฏ

final steeple
#

You could compare it to RAII in C++, but that's probably a bit of a complex answer lol

#

The short answer is that it's for when you need to guarantee that something is cleaned up

#

For example, to avoid memory leaks or similar issues

sly grove
#

It should be used wherever possible pretty much. It'll save you from memory leaks and orphaned file handles all over the place

final steeple
#

๐Ÿฅท

tough tulip
final steeple
#

Most of the time (for example, a SafeHandle) things will be eventually cleaned up by the GC yeah

#

That said, you should always call dispose at the right time when you can

rigid dagger
#

@final steeple for file:// I get a "Not allowed to load local resource" in WebGL

final steeple
#

Sounds like a CORS issue

rigid dagger
#

well no it's normal

#

and for your code I checked the URL after "using var www = UnityWebRequestMultimedia.GetAudioClip(builder.Uri, AudioType.MPEG);"

#

this make somehting like this :

"file://localhost/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3"

#

so same issue

final steeple
#

Should be able to set Host to null in the builder

#

Which should fix that I believe

#

Unless it's the web request API teanslaring it again

rigid dagger
#

the web request API will always apply it's own rule when it get an URI it seems

final steeple
#

I'm glad I don't do web stuff lol

rigid dagger
#

^^

final steeple
#

I use the web request API to load assets, but you don't have to worry about this problem specifically on desktop and console

rigid dagger
#

well, I can load assets in persistentDataPath with System.IO.ReadFile for example

#

I can "load" my mp3 with that this will work, but will only load the binary data from the file, not an AudioClip

final steeple
#

Yeah that's no surprise to me

rigid dagger
#

and there is no easy way to create the AudioClip from that ><

final steeple
#

The problem is just figuring out the right URI

rigid dagger
#

well, the right URI is "/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3"

final steeple
#

Well that's not exactly a URI

#

Not in the same sense anyway

rigid dagger
#

yes ^^

#

System.IO.ReadFile("/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3"); is a proof that this is the right path

#

but this will always be reworked by UnityWebRequestMultimedia because he think it's a relative path ><

final steeple
#

If the file was a WAV and not an MP3 it wouldn't be too hard to read the sample data manually

#

What happens if you remove the leading slash?

rigid dagger
#

I will test that

#

I think he will try to find the ressource from the folder of the project

#

and that will fail because there is no "idbfs" folder here ^^

final steeple
#

You could also try manually passing "file://idbfs/..." without using UriBuilder as a test

#

I'm not sure why localhost got added

rigid dagger
#

already tried that

#

same "Not allowed to load local resource" issue

#

because IndexedDB is not really the same kind of file system from WebGL

final steeple
#

That is very strange, as far as I'm aware file: is the correct scheme for accessing it

rigid dagger
#

tested with the leading slash removed : 404

#

because yes this try to find a folder "idbfs" in the folder of the uploaded project ^^

final steeple
#

Yet another case of a functionality gap in Unity then, it seems

robust citrus
#

i'm getting started with localization and i'm trying to decide how to structure my string tables for a card game. i have a Card ScriptableObject type that'll have multiple localized fields (name, description, etc). should i have a single "Cards" string table with multiple entries per card (CARD1.name, CARD1.description, CARD2.name, CARD2.description)? or one string table per field (for example, a CardNames string table with CARD1, CARD2, etc. entries, and then a CardDescriptions string table with parallel CARD1, CARD2, etc. entries)?

undone coral
#

it has a type for this purpose, called something like localized string reference

undone coral
#

why are you trying to write files in webgl

rigid dagger
#

@undone coral to get them next time I will start the project

undone coral
#

pass a url

rigid dagger
#

will not change the issue

undone coral
#

as a string

#

observe

rigid dagger
#

url will be reworked

undone coral
#

this is the source of your issue

#

as far as i can tell, it will resolve your issue

rigid dagger
#

fact is, I already tried ^^

undone coral
#

did you though

rigid dagger
#

UnityWebRequest still change the URL

robust citrus
#

(already got it set up and working with LocalizedStrings)

undone coral
#

override the absoluteUri property

#

it isn't sealed

#

try passing this modified Uri file

#

because the code inside unity web request is spaghetti

#

with regards to a string url versus a Uri uri

#

absoluteUri is not marked virtual though... kind of tricky

#

so if you want to fix the url issue it's going to be tough

rigid dagger
#

the issue is clearly not with absoluteUri , it's UnityWebRequest based on the documentation : if the URL/URI path start with "/" it will be considered as a relative path and this will automaticaliy rework the path to add the host website at the start

undone coral
#

this should help you figure out what url to pass

sick robin
#

Hello, does anyone have any experience with Photon? I am trying to make my player jump on one client it does a full jump and on the other client it does the most miniscule hop. how can i fix this issue

rigid dagger
#

well, I can't really do anything

undone coral
#

i think the rows are the cards (by id), and the columns are the fields of the cards

#

but it sounds like you should really have the card scriptable object reference a single totally localized object of strings

rigid dagger
#

a need to find a way to change the start of the URL to avoid "/" but something that will still point to the same resource location

undone coral
#

you can also try ticketing this issue with unity

rigid dagger
#

@undone coral already done , but without answer ^^

robust citrus
undone coral
#

i think you do

#
// localized
public class CardStrings : ScriptableObject {
 public string name;
 public string description;
 ...
}

[Serializable] public class CardStringsLocalized : LocalizedAsset<CardStrings> {}

// not localized
public class Card : ScriptableObject {
  public CardStrings cardStrings;
  public int attack;
  public int hp;
  ...
}
#

then turn card strings into a localized ref or whatever it's called

#

otherwise it's way too clunky

robust citrus
#

yep, i like that

#

however, still have the same question about how to structure string tables

undone coral
#

i mean, it's all a little clunky

robust citrus
#

one card table? or multiple tables, one per card field?

undone coral
#

then it would just be the CardStrings object

#

so you would only need 1 table

robust citrus
#

cool ok. so the table would have entries like

#

rather than a name table (with CARD1 and CARD2 entries)

#

and then a separate description table (also with CARD1 and CARD2 entries)

undone coral
#

i updated it

#

no

#

you would use LocalizedAsset instead of localized string

robust citrus
#

ooooh

undone coral
#

this will trade one kind of clunk for another

#

but i think in a positive way

robust citrus
#

this is news to me, i didn't realize you could create groups of localized strings like that

undone coral
#

well you can localize any asset

#

the asset table will Just Work

robust citrus
#

i see! i knew you could localize strings/textures/audio

undone coral
#

it will show you each card's fields

#

so instead of string tables you can use asset tables

robust citrus
#

but didn't realize you could do anything

#

right

#

that makes sense

undone coral
#

then it will be the thing you really want

robust citrus
#

that's way easier,

undone coral
#

cool

robust citrus
#

thanks!

undone coral
#

yes assemble everything that really needs to be localized

#

into its own dedicated asset

robust citrus
#

yeah this is like my ideal solution. love it. thank you!

undone coral
#

then reference it from the gameplay only asset (i.e. your card)

mellow wind
#

๐Ÿ‘‹ Does anyone have strong opinions on quality tooling/automation for small unity teams? I'm transitioning from web eng to game dev and i'm trying to get as close to my Enterprise SaaS โ„ข๏ธ workflow as possible. I'd basically like

I'd prefer opensource/free but paid solutions work too. I'm also able and willing to setup infrastructure in something like AWS if it makes sense.

My stack right now is Unity2D 2021.3.0f1, Rider and GitHub/git

Let me know if this question makes more sense in #497872469911404564 or another channel ๐Ÿ™

small badge
#

Not really an answer to your question, but: I think properly communicated and agreed code styles/naming conventions make far more sense than programatically enforced ones, especially for small teams.
But then I'm one of those people who thinks that knowing when it's better to break those rules is almost as important as following them in the first place.

#

For Smart Merging I've seen it fail as often as it succeeds, and the problem is that neither humans nor merge tools are great at looking at a merged YAML file and reliably determining whether or not it's correct. I would personally prefer to use a system of file locking (and of course correspondingly try to maximise distribution of scenes over different files/minimise the breadth of responsibility of any one file).

undone coral
#

game.ci isn't going to work... use unity cloud build

#

it will take some time before you can merge a scene. it really depends what kind of game you want to make

#

if you want to use git, you can use https://alanedwardes.com/blog/posts/serverless-git-lfs-for-game-dev/ for a realistic LFS solution since github's lfs runs out of transfer quickly

#

it isn't really practical nor advantageous for 99% of people to have automation for their unity games

#

it will be difficult to do if you are not familiar with build tools like gradle or bazel

#

i suggest trying to write the game and crossing that bridge when you get there

undone coral
#

that payoff you get from doing colossal amounts of meaningless faff in webshit/yavascript land doesn't exist in an environment like unity

#

hope that makes sense

mellow wind
#

I like the automation to prevent the faff ๐Ÿ˜„ . Especially in some newer languages like go/rust where they just decided the One True Style for everyone and made it part of the language. Specifically though for this team I wanted everything to be automated since a couple of my friends working on it don't have a ton of coding experience and I know they're going to stress out about keeping everything tidy so I'm trying to get computers to do it for them

#

Cloud Build looks like what I want though, idk how i didn't come across it during my googling. Thanks ๐Ÿ™

undone coral
#

okay well i'd skip the linting and formatting because it's going to cause more harm than good

crystal galleon
devout orbit
#

Hi everyone, I would like to know what is actually needed in terms of technology to build an online game.
I'm asking this because I've seen a lot of different solutions, but I can't seem to figure out what to use and when.So for example I would like to make an online game similar to the old pokemon games. Things I would like to have are the following

Login/Register - People need to be able to create a account login etc.
Multiple server worlds - This would represent the world the players are in something like World - 1
Chat - That would reach out over all worlds.

I've had some experience messing around with all of these things but still, I never seem to be satisfied with the result.In terms of technologies, I would like to use Unity & regular C# as backend.

These are some questions I can't seem to wrap my head around?
1 - I've made an API with .net core and a login system, so my client logs in and receives an authentication token.Now I would like my user to pick a world where he should connect to a game server, how should the game server be aware of his authentication code? Should the API have a connection to the world?

2 - A user is walking around in my game server and he picks up an item, it's added to his inventory and now I would like to inform the database this user has an item, and right now I'm using .net core for that with the EntityFramework which I would like to remain using. Would the server make a call to the .net core API as well?

It would be really helpful if anyone could share maybe a diagram of how to flow should be with the connections.

undone coral
#

I've made an API with .net core and a login system, so my client logs in and receives an authentication token.
hmmm...

#

this is a long journey

#

can you say a specific game?

#

or are you saying, "A multiplayer take on the gameboy pokemon single player adventure games"

devout orbit
#

Well yea, its called PokeMMO. I would like to know how to build a system similar to this in terms of technologies

#

I'm not planning on building the whole game, but I would like to understand to make logic and setup for it

undone coral
#

okay

devout orbit
#

So I would like to have a small world and no story line, just where people can turn base battle against each other

undone coral
#

okay

#

so you're really saying pokemon showdown?

#

are you aware of that game?

#

it's open source

devout orbit
#

Well it's not about the battles, pokemon was just a reference.
My question is more related how to setup your base of a project for something similar to my example above.

I've just looked at Pokemon showdown, but although it is open source it is written in type script.
And not really what I'm looking for.

For example It would be really helpful to have a diagram of the architecture from client to server, who's accessing the database and from where those kind of things

undone coral
#

have you created a unity game before?

devout orbit
#

Yes, I've made multiple games and I'm currently working in the industry

undone coral
#

okay great

#

there aren't many production multiplayer games with unity clients whose source code / libraries you can see

#

it usually isn't essential that you operate the backend, in fact it's a huge distraction

#

so something like photon operates like a big pubsub messaging system with some affordances for a "host" that is just "data that persists without a unity client"

#

this serves a lot of people's needs

#

for a game like this, you don't necessarily need to operate your own server. i believe photon has a way of expressing rules on how the client can modify data, which would be sufficient to prevent a lot of kinds of cheating. essentially it is the same thing as running an authoritative server, but for something suitable only for turn based / high latency realtime games

#

in terms of an architectural diagram, it really depends what exactly you want to run where

#

there's the business logic of your game. does it use unity? this has a very different architecture than if it does not

#

for example - do you want to use unity to resolve the rules of movement in your game, or will you resolve it yourself?

#

most people use unity because it makes it easy to express rules for games. if you don't do that, if you write your rules in pure csharp, you might as well not use unity

#

does this make sense?

#

you're talking about auth apis, but you haven't discovered the word "zero trust" yet, so that stuff isn't super valuable to you

devout orbit
#

For my knownledge it is important to learn what technologies are needed.
But I agree it is a huge distraction and a lot of work.

The goal is not to make a game but to learn how to do it.
There are a lot of companies in the Netherlands making these games, and having
knownledge could make a big difference.

So I agree what you are saying, but I would like to learn about how to setup the basic's of an small MMO world

undone coral
#

personally i would use photon for everything

#

this is coming from someone who operates a backend

#

for a live multiplayer unity game

#

that doesn't touch photon

devout orbit
#

The companies I worked at always used smartfox or their own custom servers

#

and a backend team ofc

#

And used php

#

But I never understood how to those worked together

#

I usually did the front and they gave me a end point thats it

undone coral
#

go tit

#

in principle smartfox is... a big pubsub messaging thing

#

it is, trust the clients completely and pass around data

#

that's the architecture

#

every client gets a copy of the data and runs its little copy of the game, and can change anything anywhere

devout orbit
#

Well we never trusted the client, we verified everything server sided

undone coral
#

did you use unity to resolve rules?

#

for example, did you have a character that moves around a world that has colliders?

devout orbit
#

What do you mean by rules exactly?

#

No, we do not have a game like that. I'm working on poker games

undone coral
#

and the rule "the user can only move within these boundaries" is resolved by "unity physics"

#

okay, so then you can see how different these things are

#

because you're showing me pokemon, and that's a character moving around

#

and it needs unity rules

#

poker games? you would run a backend that has the whole rules of poker in it

#

and you give stuff to unity to render and that's it

devout orbit
#

Right, well not really ^ ! It would be a grid and tile 5,5 = collision

#

server sided

#

I get how to backend handles poker

#

But I can't understand how the login API and authentication works and who and when talks to the database

undone coral
#

i see

devout orbit
#

You login in to my game through a .net core API there is no connection here right

#

you would only have authnetication code

undone coral
#

in a modern application, login uses a standard called OIDC

#

your unity game redirects to a website where people punch in their usernames and passwords, and in exchange the unity game gets a piece of text that is their user ID cryptographically signed by an authorization server

#

it sends that piece of text to your backend to prove the user is who they say they are

#

in http, this would be in an Authorization: Bearer XYZ header (for example) or for a website, a cookie

#

then your backend reads this piece of text and extracts the user id from it

#

and uses it to query the database, show people their balance, etc.

devout orbit
#

But that would still be connectionless

undone coral
#

yes exactly

#

that is a feature, not a bug

#

you can attach the piece of text to a connection

devout orbit
#

I agree, but I'm looking for the combination for a live connection and this API ^

undone coral
#

you attach th epiece of text to a connection

#

it's a standard piece of text

#

every programming language has a way to decode it into a user id

#

it's up to you how you want to do the connection

devout orbit
#

So you establish a connection and you would assign the piece of text to the connection?

undone coral
#

some people use websockets. i use grpc. these both support long-form connections

#

you would send the text through the connection

#

presumably

#

some things like grpc already support Authorization: Bearer...

#

because it's a standard

#

grpc is hard to use in other ways though

#

but your login thing doesn't manage a connection

#

it doesn't care

devout orbit
#

Right, but my server wants to know who he is

undone coral
#

your game works whether people say they are who they say they are or not

devout orbit
#

and if it is valid

undone coral
#

that is proven by the text

#

anyway, you don't really Know what OIDC is until you use it

#

you wouldn't write your own auth server

#

you could use auth0, okta, cognito, playfab, apple's identity system, they all give you oidc

devout orbit
#

No, definitely not. Right now I used JWT

undone coral
#

see

#

i avoided using the word jwt

#

because you HAVE indeed done what i am describing

#

because that piece of text is a JWT

#

the JWT part isn't essential

#

it's understanding how login is something you get from a vendor, and you get a piece of text that proves who you are

#

anyway

devout orbit
#

Right, but thing I'm not quite getting is how does the server know what that piece of paper means

undone coral
#

there's a library that decodes JWTs

#

it ships with aspnetcore

#

and vertx, and spring, and express, and...

#

and there's always a field in there called "uid" i.e. the user id

#

and that's it

#

if you wanna ship the user's name in there you can, or it can ask for that data from the identity server (okta, auth0, cognito, keycloak, ...), also via a standard

devout orbit
#

But it could be faked right? I mean if you'd find out what your code is on your client and pass it to me

undone coral
#

no

#

because it's signed with a private key only the identity server has

#

anyway this doesn't really have to do with games

#

it sounds like you should punch oidc into google

#

but it's really the least important part of what you're doing

#

the whole point of all this dance is that people reuse their passwords, so the powers that be have decided "you shouldn't directly receive a user's password, please just use Facebook login or Okta or whatever"

#

of course a username and password together prove who someone is

#

but then you're receiving someone's password

devout orbit
#

Well I don't really have anythings that is more important then the other I'm trying to familiarize myself with the bigger picture.
And if a product owners comes to me I could consult him in to that what we need

undone coral
#

you sort of engineer your game totally orthogonally to people proving who they are

#

because doing that is really easy using the standards

#

and it means you can easily test your game, make robust automation, etc.

#

so you get this user ID

#

it comes with every request, or it comes with the connection

#

that's pretty much it

#

if you want a bidirectional channel, it's extremely painful to use grpc in unity right now

#

but it works

#

the fact that it's hard to use is one part of why Photon exists

#

this is a good multiplayer framework from the people who operate Shadowverse

devout orbit
#

So the clarify, as user received a verification text from the API.
and he continues to use that verification to communicate in the live connection of the game server.

I will look at magicOnion I've heard about it before

undone coral
#

and he continues to use that verification to communicate in the live connection of the game server.
OIDC specifies all sorts of stuff and pre-existing libraries just Do the right things for you

#

but yeah, that's pretty much it

#

you send this piece of text (the JWT)

#

with your connection, and the server... stores it in a variable

#

don't overthink it

devout orbit
#

But for example your token = 1234
And I would sniff that packet,

Then I would force my client to modify the token to be 1234 and match yours, if is it possible to represent my self as you?

#

I will try to learn more about this topic

undone coral
devout orbit
#

What is your role in the gaming industry if I may ask?

undone coral
#

i am an engineer

devout orbit
#

As senior or ?

undone coral
#

yeah

devout orbit
#

Ah, I'm now working as medior front end developer

undone coral
#

you're in a good place but you want to follow the standards

devout orbit
#

And where are you located

undone coral
#

san francisco

#

๐ŸŒž

#

๐ŸŒ‰

devout orbit
#

Nice, cool! I'm from the Netherlands ๐Ÿป ๐Ÿšฌ

undone coral
#

lol

devout orbit
#

Do you maybe have a specific guide or book in mind?

#

That elaborates on these topics well?

#

Seem you learned a lot through experience

undone coral
#

but is pretty complicated

#

the front end is closed only because i use a lot of paid code assets

#

the improbable.io people wrote a lot about engineering multiplayer unity games but i'm not sure how valuable it is now

#

and anything the cygames guy writes is good

devout orbit
#

I will also take a look at the magic Onion one

undone coral
#

one thing you can consider with your experience is something like postgraphile

#

you can pass a token to it directly, and write your game rules in SQL

#

it supports subscriptions, and graphql works over websockets so it's less painful

#

postgraphile decodes your jwt into sql variables you can use in statements and row level security

#

this is if i had to write an MMO today, what i would do

steel snow
#

I am kind've confused how i use the job system, i made a simple parallel job that checks a collection of numbers and returns the index of where the number is (or -1 if not found) but it always returns not found even when its in the collection.... now sure what i am doing wrong... this is my setup:

public struct MyJob : IJobParallelFor
{
    private int seek;

    private NativeArray<int> result;

    [ReadOnly] private NativeArray<int> values;

    public MyJob(int seek, in NativeArray<int> values, NativeArray<int> result)
    {
        this.seek = seek;
        this.values = values;
        this.result = result;
    }

    public void Execute(int index)
    {
        int input = values[index];
        if (input == seek)
            result[0] = index;
    }
}
public class Test : MonoBehaviour
{
    [SerializeField] private int seek;
    [SerializeField] private List<int> _data;

    private void Awake()
    {
        NativeArray<int> numbers = new NativeArray<int>(_data.Count, Allocator.TempJob);
        for (int i = 0; i < _data.Count; i++)
            numbers[i] = _data[i];

        NativeArray<int> result = new NativeArray<int>(1, Allocator.TempJob);
        result[0] = -1;

        var job = new MyJob(seek, numbers, result);
        job.Schedule(numbers.Length, 1).Complete();

        if (result[0] == -1)
            Debug.Log("Not Found");
        else
            Debug.Log("Number found at Index: " + result[0] + " :: " + numbers[result[0]]);

        numbers.Dispose();
        result.Dispose();
    }
}

any ideas what i might have misunderstood?

austere jewel
steel snow
#

it does now im getting index range issues

#

im guessing each job can only access result[index] and cannot all access result[0] ?

austere jewel
#

Add [NativeDisableParallelForRestriction] above result

sly grove
#

Wish that wasn't such a bludgeon

#

Would be nice to have that per-native-collection

austere jewel
#

It is?

steel snow
#

@austere jewel nice that worked! ๐Ÿ™‚

#

thanks

sly grove
#

Carry on

steel snow
#

dont suppose you know what this actually means:

#

the docs used 1 but they didnt really explain what it means

sage radish
steel snow
#

so its like loop unrolling ?

sage radish
#

The docs include this comment:

// The second parameter is the batch size,
// essentially the no-overhead innerloop that just invokes Execute(i) in a loop.
// When there is a lot of work in each iteration then a value of 1 can be sensible.
// When there is very little work values of 32 or 64 can make sense.

sage radish
steel snow
#

๐Ÿค”

#

hmm

#

so if i put 2 - each thread will do i and i+1 ?

#

essentially 2 indices per thread of the work

#

@sage radish

sage radish
sand raven
#

im planning to make a minning game that will have hexagonal grid dirt chunks. What would be the best way to handle chunks object-wise? Would it lag if I were to make every hexagon its own object or is there a better way to handle that?

gray pulsar
sand raven
lost dove
#

Is it possible to run some code before my build's game window appears? I need to initialize Steamworks, but I would ideally like the application to do this before the builds main window appears, before showing the splash screen and such

#

The reason for this is because I show a windows messagebox stating that steam needs to be initialized for the game to run, and I would like the messagebox to appear first (if needed) before splash screen and everything

fallen magnet
#

What do I need to learn in order to have the player draw something on screen and score it based on how closely it resembles the figure on screen? Ikai has this mechanic, for instance.

undone coral
undone coral
#

what would make the best gameplay? another interesting question dr. p

undone coral
lost dove
#

I don't think it's possible from what I've gathered from Google

fallen magnet
undone coral
#

are you sure? there's an argument to runtime initialize on load

undone coral
#

i would watch some slow motion video and read a little about the physics, and it'll be clear how to use a material and a mask texture to do it

lost dove
#

When using Application.Quit()

#

Actually it seems like Environment.Exit() seems to solve the window flashing issue. This should work. Thanks again!

stuck onyx
#

I've been researching and got to the conclusion is not possible to change this values in runtime if its not using quality levels. Can someone confirm it's like this? im using Unity 2020.3.30 and built in render pipeline

flint sage
#

That's their point, you can only change it using quality level

stuck onyx
novel plinth
#

oh!

stuck onyx
#

aha, okay, thanks, are you sure about that then?

#

only way is qualitylevel, i can stop wasting time researchig

flint sage
#

Oh no I have no idea, just making sure your point is clear

stuck onyx
#

ah i misunderstood ;D

#

๐Ÿ˜„

flint sage
#

QualitySettings.shadowDistance = 1; seems like it's there?

stuck onyx
#

yeah but it doesnt work in runtime

#

it does in editor though

flint sage
#

Ah

stuck onyx
#

anybody? could confirm quality levels is the only way to modify quallity settings in runtime please?

frozen imp
stuck onyx
#

oh, if its like that we can't use it the

#

then

frozen imp
#

Also it may have different behavior in the build

stuck onyx
#

we want to modify shadows quality when user zooms in

#

its a citybuilder

#

hmmm

#

we will try to build youre right

stuck onyx
#

no, it doesnt work, it works on editor though

#

in device i call to change the shadow projection but there's no change

fallen magnet
# undone coral pen on paper like photorealistically?

No, sorry. I'm still trying to figure out the language to describe the problem space. Here's an example of what I'm looking to do: https://youtu.be/0jLkaq3sJzc?t=1854 (You don't have to watch the whole thing, it's on the correct time stamp)

PC Gameplay Walkthrough. Part 1. Monsters, ghosts and spirits attack the shrine as a defenseless priestess tries her best to survive.

โ–บFollow me on Facebook - http://on.fb.me/1u0sffi
โ–บFollow me on Twitter - http://Twitter.com/CjuGames
โ–บJoin me on Discord - https://discord.gg/n657S3k
โ–บSupport me on Patreon - https://Patreon.com/CjuGames

โ–บMore I...

โ–ถ Play video
undone coral
undone coral
fallen magnet
undone coral
#

In mathematics, the Hausdorff distance, or Hausdorff metric, also called Pompeiuโ€“Hausdorff distance, measures how far two subsets of a metric space are from each other. It turns the set of non-empty compact subsets of a metric space into a metric space in its own right. It is named after Felix Hausdorff and Dimitrie Pompeiu.
Informally, two sets...

#

@fallen magnet peruse any existing code implementation from keyword search "hausdorff distance github two images"

#

i'm not sure yet if this is appropriate for games lol

#

i think don't overthink it

#

you would just compare two super low resolution downscales of the iages

#

as binary

#

and if they're the same they did it right

#

does that make sense?

#

i sent the real answer, if you were doing proper strokes, but i don't htink you need that

#

like take the two images (target and draw) and turn it into a 5x5 binary grid where it's true if there was ink there and false if there was not. then compare. if they're the same, the player drew the target

fallen magnet
undone coral
#

i seriously doubt this ikai game did hausdorff

#

but i was making a game ONLY about drawing then i'd implement it

#

this thing is apparently really really good at doing this kind of illustrated image comparison

#

that it would tell the difference gameplay wise between asking the player to draw an image in a different spot (as opposed to directly superimposed)

undone coral
fallen magnet
undone coral
#

phew

fallen magnet
#

Why?

undone coral
#

just checking

#

i can't help people not using event system with UI games lol

#

it's too hard

#

i wanted to make sure it wasn't all for naught

fallen magnet
#

Gotcha. I imagine it's a common beginner mistake

#

I'm a web developer so I tend to think in events anyways

timber sapphire
#

Guys, Lets say I have 10 slots and in slot 2 is a item with the id 1 and with the amount 3, in slot 5 is an item with the id 2 and amount 5 and in slot 8 is an item with the id 1 and amount of 7. So I want a for loop that goes threw all the slots and if it finds one with an item in it, it adds the id of it in the array A and the amount of it in array B. But if the id is already in array A than it should not ad it and just increase the value of the item by its amount in array B. So that the arrays are like this: Array A: 1, 2; Array B: 10, 5; and NOT Array A: 1, 2, 1; Array B: 3, 5, 7;

undone coral
#

what is your objective

#

lol

#

this is some real school mathproblemese

#

you can use linq to make transformations of arrays

timber sapphire
#

this is for my game xD

undone coral
#

you should explore linq

#

you can use GroupBy to group the items by their ID, then sum their quantities

#

then you can "unzip" (this doesn't exist in linq) to turn an array of objects of {Id, Quantity} into two arrays {Id} and {Quantity}

#

you can also achieve this without linq. create a dictionary mapping ids to quantities, then iterate through your items incrementing the quantities.

timber sapphire
#

uff

undone coral
#

then enumerate through the dictionary, put the key in one array and the value in another

timber sapphire
#

i dont even know if i need this

undone coral
#

it's hard to tell because you didn't tell me your objective

#

which was the first question i asked

timber sapphire
#

Like my goal is that I can craft an item, that works but its not using any items for it. for example if i want to craft an Axe and I need 4 amounts of id 1 and 2 amounts of id 2 so the bool canCraft is true. how would you do that

fresh salmon
#

To count if you have enough items in your inventory to be able to craft something? LINQ

undone coral
#

by trying to do this in LINQ it's like you get an upgrade for your brain

#

does that make sense?

timber sapphire
#

yis

undone coral
#

so that's why it's not super valuable if i just hand you the answer

boreal elm
#

i dont know what to do

#

my vehicle be spinnin

#
    private void UpdateSingleWheel(WheelCollider wheelCollider, Transform wheelTransform)
    {
        Vector3 pos;
        Quaternion rot
;       wheelCollider.GetWorldPose(out pos, out rot);
        wheelTransform.rotation = rot;
        wheelTransform.position = pos;
    }
}

``` I am not familiar with quaterionons how do  i reverse the rotation
novel wing
#

Can I write to the Unity Console in a Source Generator? For debugging code generation

plucky laurel
#

is it called from unity?

novel wing
#

Err I'm not really sure, I suppose it kind of is? It's the C# Roslyn Source Generator. I'm currently trying out some basic code generation and was wondering if I can somehow output what's going on.

plucky laurel
#

yes from where do you call roslyn api

novel wing
plucky laurel
#

if you have access to Debug class, it should work

#

you can reference UnityEditor assembly, should work

#

you can also most likely just throw exceptions

novel wing
plucky laurel
#

since its unity that captures them, youll see them in console

mighty lion
#

Hey guys!,I have a question

#

Can a game be made mixing visual scripting and coding at the same time?

#

like using both?

#

And What I mean by visual scripting is (Bolt)

novel wing
# plucky laurel since its unity that captures them, youll see them in console

After some experimenting it seems that neither an exception or a Debug.Log() appears in the console. At first I was confused because Rider didn't realize the scripts were being recompiled and the generated files updated, so I always seemed to have an old generation. However now that I know that's not the case there seems to be no way to output any debug info.

#

Yeah there seems to be some issue of script recompile not applying properly that's making this extremely confusing at the moment. Some combination of reimport + restarting Rider seems to update the code gen (or what Rider thinks the code is), but I am not sure which. It's probably related to that I am on Unity 2020.3 but I've seen articles use 2020.2.

modern storm
#

Hi, I'm using RaycastCommand to set the Y Position of my AI units. When going into stairs the vertical movement is obviously choppy with each stairs. Is it possible to interpolate using the new and last known pos? When lerping I usually do it between the starting pos and the destination but I can't rely on this here as our collision avoidance changes the position so I don't know the final destination.

humble onyx
novel wing
modern storm
#

It's kind of complicated, I use the RVO system from Astar Pathfinding, it works in xz only and the return value of Y is always 0

#

I have access to the last frame's height, which I have to merge with the ground check and the xz of the RVO simulation.

#

Maybe its not complicated but my brain is toast right now

novel wing
#

I don't see why you couldn't just do height check in LateUpdate? Or manually change the script execution order to make sure that all movement is done by the time you interpolate height

modern storm
#

So I do the ground check on the new XZ value but using the last frame's Y value (1 frame shouldnt matter much)

#

well it is done actually

#

Im just not sure how to interpolate it as I usually lerp over time over multiple frames

#

I never used lerp on two value over a distance

tired cradle
#

Trying out Netcode for gameobjects, but hitting a hiccup immediately:
IsLocalPlayer is returning false on the local player object that spawns when a client connects to the server

novel wing
novel wing
modern storm
#

So do I just do Math.Lerp(oldPos, newPos, 0.5f) ?

novel wing
#

sure

#

it won't actually be a linear interpolation though, it will just approach the newPos at 50% each frame

modern storm
#

oh ok, I usually do the * times.deltatime thing which got me confused here.

#

so its like an average

#

may as well add up the values and do * 0.5f

#

wont be smooth though

novel wing
#

It will be smooth as it will approach the correct value over time

plucky laurel
#

apart from writing simple code, is there a way to ensure that decompiled code looks verbatim like the source?

tough tulip
# plucky laurel apart from writing simple code, is there a way to ensure that decompiled code lo...

if you mean something like ILSpy then no.
it depends on the developer of the decompiler how they actually want the decompiled code to look like.
but to prevent errors,
Avoid switches. most cases they work but in cases where return and break are used for different cases, it will usually end up with weird decompiled results. Async codes are also not fully accurate and ended up with some syntax error

plucky laurel
#

thought so, thanks

languid dove
#

I hate to do this , but I've got a shader question :(

I've downloaded PSXEffects from the asset store and it works until I turn on 'post-processing' on the script . It's throwing this error message

invalid subscript 'rgb' at line 96

#

Can't figure it out , someone who's smarter than me help a brother

#

Shader code may as well be latin

wooden cedar
#

You'll need to look at line 96 and see what rbg is

#

But it sounds like your unity is the wrong version for what PSXEffects was made for

#

So you may need to edit some shaders

languid dove
#

it's just written in a language I never learned

#

(sorry in advance for gross code dumping)

#
                for (int x = 0; x < DITHER_COLORS; x++) {
                    if (x == index) {
                        c.rgb = clamp(x.rgb * (DITHER_COLORS - 1) + DITHER_THRESHOLDS[x] * (intensity * 100), fixed3(0, 0, 0), fixed3(DITHER_COLORS - 1, DITHER_COLORS - 1, DITHER_COLORS - 1));
                        break;
                    }
                }```
#

so the x.rgb and the c.rgb apparently doens't exist ?

#

but like , doens't it ?

wooden cedar
#

I'm not sure where c is being defined mmm

languid dove
#

c is getting passed in via a method

#

hang on , let me find that part of the code too

wooden cedar
#

But my guess is either c or x type isn't defined or its using a shader thing that doesn't have .RGB anymore

languid dove
#

float3 GetDither(float2 pos, float3 c, float intensity)

#

that's the method name

languid dove
#

Hey mate , I'm just on my laptop at a holiday home and we're going to the pub now lol . But I appreciate ya trying to help , I will probably be back

#

<3 ty for your time

wooden cedar
#

I think anyway

languid dove
#

/:

#

that also makes sense , but I guess what doesn't make sense is why it would ever be written otherwise ?

#

like , this shaderpack is a proper pack with thousands of downloads

#

haha

wooden cedar
languid dove
#

aH

#

so it's converting the float3 into rgb values

wooden cedar
#

Well only that guys forum or the author knows why

languid dove
#

because that makes sense

#

Bril

#

thanks bud <3

wooden cedar
#

Might not work, I'm pretty green at shaders

#

x would break too, it's an int, so no rgb

#

My guess Unity shader auto conversion broke some type?

fierce wind
#

The video show the problem:
I was doing camera for third person game and i got into a bug when I move backwards (toward the camera position) the camera "sallow" the player
its to much code files for me to send in here So please DM as soon as possible

languid dove
#

makes me wanna learn shader code

mighty lion
gray aspen
#

hi @languid dove float3 variables can access their scalar values by using .xyz, .rgb but this is just syntactic sugar, in fact you can use something like .xxz that means that the newly constructed float3 variable will have x value of the original vector on the first and second value, and z on the third (it's called swizzling). The reason for both conventions existing (xyzw, rgba) is just convenience. Reference: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx9-graphics-reference-asm-vs-registers-modifiers-source-swizzling

wooden cedar
gray aspen
#

oh sorry, wrong at

#

@languid dove looking at the code provided, you define the for-loop with x ** as an ** integer, but you're trying to use it as int3/float3 as you use x.rgb that does not make sense as the x is only single dimension

slender tusk
#

Hi everyone, I have a little question. I found the IProcessSceneWithReport interface that let's me know when a scene has been built.
I tried to add a gameobject at each scene to check if it works, and indeed it does.
But for some reason, GameObject.Destroy and GameObject.DestroyImmediate doesn't work on components ?
(I am trying to use this callback to cleanup all my scenes before building...) Thanks for the help!

languid dove
novel plinth
slender tusk
# novel plinth if it's still in Edit mode then DestroyImmediate should work `UnityEngine.Object...

Ok my bad, it wasn't working because basically what I was trying to do is loop over all the gameobjects, get the components that are null and then destroy them with destroy immediate (which wasn't working) i just had to use GameObjectUtility.RemoveMonoBehavioursWithMissingScripts(gameObject)....
(I need to remove missing script after conditional compilation (don't know if it's the real name), so that I don't have "missing script on..." when building server only game for example) Thanks again!

lunar lantern
#

hi

#

i'm having a json file in Application.persistentDataPath for saving/loading game progress

#

I build for Android

#

now im having a new version of the game which requires overwritting the data in that json file

#

how can i make the game run some scripts once on installing a new version with higher version code?

final steeple
#

You could store a version.json file that contains version information

#

If the file doesn't exist, assume it's an old version from before that file was implemented

lunar lantern
#

thanks for answering! gonna give it a try

true cosmos
#

hi, can you cache your coroutine as IEnumerator? i see that once it completes first time it doesnt run again for 2nd time, when called. Thats intended behaviour?

#

heres code

agile yoke
#

Yes, this is expected behaviour. The IEnumerator effectively stores one specific call/execution of the coroutine (which you should only call StartCoroutine on once)

#

If you want to store "a coroutine function I can start a new run of whenever I want", the type for that is Action<IEnumerator>. So if you had a Action<IEnumerator> coroutine, you could call StartCoroutine(coroutine()) (note the ()) as often as you want and start a new one each time.

undone coral
true cosmos
#

so always with brackets - for short? ๐Ÿ™‚

undone coral
undone coral
#

i don't know what word to describe it, but it is passing the object returned by the IEnumerator X() method directly to StartCoroutine()

true cosmos
#

ok, thank you. I cannot get to understand what this IEnumerator object is but you can say its some sort of low level under the hood code?

undone coral
# true cosmos ok, thank you. I cannot get to understand what this IEnumerator object is but yo...

an IEnumerator is an API and state for an enumeration, meaning going through elements (potentially infinite) of a sequence. its methods MoveNext and Current are the API for going through this sequence. coroutines in unity hijack the fact that code is executed between yield statements in an IEnumerator to make stuff happen; then, unity interprets the object that is yielded to decide how long to "wait" (like for a certain amount of time) or to wait for something else (like a unity web request to finish)

#

csharp has coroutine like functionality natively, used via async / await and Task but coroutines in unity predate the existence of async Task in csharp

sly grove
# true cosmos heres code

The IEnumerator returned by an iterator method (which is what Unity uses for coroutines) is not generally reusable. You will need to do StartCoroutine(DoSthCoroutine()) every time

undone coral
#

does anyone have experience adding assemblies & plugins via scriptingassemblies.json?

#

will this ever work on il2cpp?

trim copper
#

I need System.Windows.Forms to open a windows native save/load file dialog (for savegame export/import), and I'm having a huge amount of trouble getting it to work. I have found some solutions online, but they don't work for me. I get a compiler warning saying that the dll is not supported, and when I run the game it works fine but I get a not supported exception when I try to open the dialogs. I'm using 2021.2 with IL2CPP and .NET Framework API. But it's the same in Mono.

#

I have tried grabbing different variants of the .dll, from Windows/Microsoft.NET, from the editor installations Mono folders, from github where I originally grabbed the code that's supposed to open the dialogs.

#

Any ideas how I can determine why unity is saying the .dll is not supported?

undone coral
#

on all platforms

trim copper
#

Problem is, the author seems to have abandoned it 4 years ago

#

There are a ton of forks and stuff though, so people seem to use it

trim copper
#

The .dll is also not showing up in assembly definition override references

#

Hmm, won't hurt I guess ๐Ÿคท

frozen imp
#

@trim copper Because System.Windows.Forms.dll already exists in the editor it will conflict with it. Remove dll from the UnityStandaloneFileBrowser plugins folder and switch API compatibility level in the Project Settings > Player to .NET Framework then it will be able to use the built-in one.

trim copper
#

Huh, I have tried removing it, but not with that API compatibility level

#

I'll check that, thanks

hardy sentinel
#

it's referenced for the editor functionality only tho, right?

frozen imp
#

I am using it in a project. Works fine with this.

frozen imp
#

Have to switch framework to access in the build.

quiet bolt
#

Also dont forget to add System.Deployment.dll in your assets folders so that it can build properly

trim copper
#

Uh what? Where would I take that from and why do I need it?

frozen imp
#

Deployment is also present there

quiet bolt
#

Idr what the error was but it did say it needed it

#

Ah

frozen imp
#

2021.3.0f1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api This is the location of dlls you access with it, I think.

quiet bolt
#

Nvm found it
ArgumentException: The Assembly System.Deployment is referenced by System.Windows.Forms ('Assets/Plugins/System.Windows.Forms.dll'). But the dll is not allowed to be included or could not be found.

frozen imp
#

(Change to your editor version)

trim copper
#

I'm still getting this after removing the dll: warning: Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped/System.Windows.Forms.dll assembly is referenced by user code, but is not supported on current platform. Various failures might follow. UnityEditor.GenericMenu:CatchMenu (object,string[],int)

#

And it still doesn't work ingame ๐Ÿ˜ฆ

#

I don't know why it wouldn't be supported, building for x64 windows standalone

frozen imp
#

Make sure you've switched the framework

trim copper
#

Yeah I've done so

#

Are you using Mono or IL2CPP? 64 or 32 bits?

frozen imp
#

Mono

trim copper
#

I'll try Mono then

#

Same problem ๐Ÿ˜ฆ

frozen imp
#

Maybe need to regenerate project files as well to force project update to refresh references

trim copper
#

Ah, I'll try that, maybe restart the editor as well...

undone coral
#

what if i gave you the $10 to buy the asset

#

jk

trim copper
#

I already got it working for WebGL by investing time and sweat, don't want to lose that investment by switching to some other thing

#

Also I was kinda hoping to learn something from this, but this build stuff is just frustrating

frozen imp
#

I think I've set .NET Framework as API compatibility level long time ago in that project and took for granted that UnityStandaloneFileBrowser worked for me after I just removed its Forms dll. And then on fresh OS it lost settings and I've spent all day yesterday trying to make it work segregating it with Assembly Definitions. Was a waste of time, until I bumped into article mentioning framework change...

trim copper
#

I'd like to use an assembly definition for it anyway, just because it is its own thing

#

Well, still the same problem. Are you building for 32 bit or 64?

frozen imp
#

There might be a way to cut off UnityStandaloneFileBrowser completely with Definitions and use it with direct references from inside. I'm don't know how to set it up though

undone coral
trim copper
#

People use it, so there must be some way to do so ๐Ÿคท

undone coral
#

i believe the assets use direct invocation

#

since there's a file system dialog provided by windows

#

you can interact with

#

i understand people use it

#

i can't speak to how or why it works because i don't know

frozen imp
#

Btw with .NET Framework set it works perfectly in WebGL build and in PC build.

undone coral
#

i don't think it really matters

frozen imp
#

System.Windows.Forms gets correctly referenced in the project files from the Unity Editor api library

trim copper
#

Yeah, it also gets referenced from any Forms.dll I put into unity

#

In VS. But not during the actual build.

frozen imp
#

Wait did you add your own as well?

#

You need to remove that dll

trim copper
#

Not anymore, I removed that

frozen imp
#

then Unity uses its own with the framework

undone coral
#

you should probably use the [DllImport] for the native file system dialog

#

out of the proper dll that provides it

#

you could also use a COM library dedicate just for this probably

#

i think this is what the assets do

trim copper
#

Hmm, I'll try and find out what that is and how to do it, thanks for the suggestion

#

The problem is that the thing I'm using uses the Ookii dialogs library, and I think that also uses Forms

#

It also uses Forms directly

#

So I'd have to copy that source as well I guess

undone coral
#

no

#

i don't think it'll ever work to copy the source

#

i don't know

undone coral
trim copper
#

Thanks a lot for these suggestions, that at least gives me something to go on. I was really out of ideas.

undone coral
#

well

#

the right thing to do is to buy the asset

#

for $10

trim copper
#

People use it in unity ๐Ÿคท

undone coral
#

and just see what they do

trim copper
#

Yeah, probably

undone coral
#

what is your application?

#

i feel like you are spending a lot of time on file dialogs for no gain

trim copper
#

I just want to let people export and import saves

undone coral
#

well that's an asset

trim copper
#

It's just a hobby, so the gain isn't that important. This really is no fun though.

undone coral
#

this isn't webshit land where the libraries suck because they're free

#

it's unity where you pay for an asset and it works

#

right

#

i would pay $10 to not do this extremely unfun task lol

#

besides, it'll never work

#

you can't use ooki

#

you can't use system.windows.forms in unity

#

some people do, but it's because they munge something on their machines

trim copper
#

Again, people do it

undone coral
#

and it accidentally works

trim copper
#

Magic ๐Ÿคท

#

A wizard did it

#

๐Ÿ˜ฆ

undone coral
#

it's a very webshit perspective

#

it is too fragile to ever work

#

consistently for everyone

#

at all times

#

that said, you can use native platform stuff easily

#

anyway i'm not trying to bully you more the problem is doing that for me lol

trim copper
#

I guess there might be something in user32.dll or something

#

My experience with unity btw is that things never just work. Never ever. It's always a fight, even for the most mundane things.

#

Very annoying

#

Plus the docs are terrible

undone coral
#

your expanding brain meme sounds like:

0. System.Windows.Forms has a dialog I
   need, but it works for some people.
1. When something works for someone,
   that could be meaningless.
2. Do people really need to make decisions
   about save game files in 2022?
undone coral
trim copper
#

No haha, maybe that's even worse, I don't know

undone coral
#

hmm

#

do you have any other prior programming background here

#

i am just wondering

trim copper
#

I'm an experienced PLSQL developer, and that certainly has it's own set of horrible problems

undone coral
#

okay

#

that's pretty niche lol

trim copper
#

It's very not C#

undone coral
#

the perspective here is that there's nowhere to hide in unity. i mean you can certainly try - you can try hiding inside making a file save dialog

#

or you could buy the asset for $10

#

in other engineering environments there are a lot of places to hide

trim copper
#

Also did some Java, but I wouldn't call myself experienced regarding Java

undone coral
#

it's possible to spend a whole day... a whole year on something meaningless

#

you don't HAVE to in unity

#

it's just harder to hide when making games

#

at least the ones someone else is ever going to play

#

there's no maven or gradle, there's no dependency management, there's no upgrading constantly

#

tests are a huge pain in the ass to write... but they do not matter

#

do you see what i mean?

#

if you are experiencing a major pain point, in a darwinian way that is a signal you are not making a game

#

which is true - a file save dialog doesn't make sense

#

that's what i've been trying to talk about this whole time. just save it wherever.

#

nobody needs to be prompted for this

trim copper
#

Not really. I have so far avoided writing a lot of tests, but I think they would have been useful to have at times, possibly even a net positive...

undone coral
frozen imp
undone coral
#

so i can only help with stuff that makes sense

#

if there's a gameplay issue just post it and that's interesting

trim copper
#

Oh I'm already saving it wherever. I guess I can just have the export/import for browsers where it's really required (as long as I don't have some form of cloud save)

undone coral
#

system.windows.forms.... just save it into Documents and move on

#

sure

#

that makes sense to me

#

but in the browser, you would just save it to the web

#

same thing

#

you wouldn't prompt the user. save it anywhere, localstorage, s3, whatever

trim copper
#

Nah I have export/import to file working in web

undone coral
#

well

#

anyway you see what i am saying

trim copper
#

It just doesn't work on windows

frozen imp
#

Did you make any other changes to UnityStandaloneFileBrowser btw?

trim copper
#

Sure, lots...

#

Yeah I see what you're saying, I should cut my losses, buy the asset and move on, or just ditch the whole feature for windows standalone because it's not important.

frozen imp
#

I've tested the solution on the new project as well. It work reliably across many Unity versions I've updated to

trim copper
#

The only thing keeping me from doing that is because it feels like admitting defeat...

frozen imp
#

I don't think I've modified the source as well, apart of updating to WebRequest from WWW parts.

trim copper
#

WebGL didn't work well for me, it required clicking somewhere after clicking the button (when attached on click), and just plain didn't work when attached on mouse down like in the samples

frozen imp
#

So just dropping UnityStandaloneFileBrowser into new project, setting API to .NET Framework should work out of the box (with Form dll in UnityStandaloneFileBrowser deleted)

trim copper
#

Using UI Toolkit though, not UGUI like the samples do, so maybe it works there

#

So I had to make changes there

frozen imp
#

I made an editor for the game to create content anyone could save from/load from WebGL page with it.

trim copper
frozen imp
#

Yes, that's the one.

#

Which editor are you on btw?

trim copper
#

2021.2

frozen imp
#

I've used it in the past on the ancient one which didn't have conflicts in the first place and on latest 2021.2 builds. Also now had to install OS to a fresh drive, with only VS, Hub and 2021.3 and it works just fine.

trim copper
#

I don't think it really makes a difference, either forms is there or it's not.

#

I get the same compiler warning on a new project as well

#

That forms is not supported on the current platform

frozen imp
#

After importing this just switch to .NET Framework and it works...

#

ยฏ_(ใƒ„)_/ยฏ

trim copper
#

Not for me ๐Ÿ˜ฆ

frozen imp
#

ehhh, just to cover everything. One thing that I've installed on top of everything default is installing 4.8 targeting Framework in VS. Might not matter at all.

trim copper
#

I think it shouldn't matter

frozen imp
#

Well, dlls in Unity folder are marked as 4.8 api, so it might.

#

\Editor\Data\UnityReferenceAssemblies\unity-4.8-api

#

That's where the Forms are which you need to make use of

trim copper
#

Hmm, I'll try it then

#

It working for you but not for me makes it feel even more like admitting defeat to say screw this and move on to something fun

frozen imp
#

It really might be the targeting framework thing. Because I have basically brand new OS install and just these tools and it's working.

trim copper
#

Not getting the compiler warning anymore

#

It still crashes mono builds, but that might be because of some of the other things I changed

#

When I actually press the button to open the dialog ingame I mean

#

Yeah it's something, I'll go back to IL2CPP where error messages in the log are actually readable and it doesn't just crash...

#

Who would have thought, it may not have been a unity problem at all but a compiler problem...

#

Thanks a lot for your help!

#

I guess if all else fails I can still just move on, or try and use a UGUI ingame file browser with my UI Toolkit GUI, no idea if that's a good idea...

#

Warning is still there with IL2CPP :/

#

And same runtime error: NotSupportedException: System.Windows.Forms.CommonDialog::.ctor

frozen imp
#

That is when you build it?

trim copper
#

No, when I try to use it ingame after building

#

Build error is still this: warning: Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped/System.Windows.Forms.dll assembly is referenced by user code, but is not supported on current platform. Various failures might follow. UnityEditor.GenericMenu:CatchMenu (object,string[],int)

frozen imp
#

That's in the build for WebGL?

#

I'll try to see if I get the same thing

trim copper
#

No, il2cpp for windows standalone

#

WebGL doesn't use forms, it does some browser magic (that you can read in the .jslib file and it's pretty weird but I could understand it and do the changes I needed).

frozen imp
#

(Installing c++ tools to build it)

frozen imp
#

Problem was it was just causing conflicts

trim copper
#

From searching a bit further I think it only works with Mono. But I guess I could try putting a proper dll again and hope now that the compiler problem is resolved that will work

frozen imp
#

I've hit Linker errors trying to build...

#

I don't think I've ever used IL2CCP, it builds and works just fine with Mono though

trim copper
#

IL2CPP does "normal" ahead of time compilation, it converts the IL output of roslyn to C++, then compiles that to the target platform. While Mono does some JIT magic to make things run. Mono has better API compatibility, IL2CPP usually has better performance. Also WebGL builds always use IL2CPP.

#

I like to keep it set to IL2CPP so I know if the standalone build compiles, WebGL will as well.

#

But afaik it's fine to just use Mono for standalone windows.

frozen imp
#

Good to know! IL2CPP is also harder to decompile I remember hearing.

#

Or at least get a legible code from.

trim copper
#

You cant use anything that uses Reflection.Emit with IL2CPP, which is surprisingly many things

#

That's what they mean with "reduced API compatibility"

soft hawk
#

Anyone know how I can set the position of a UI Document relative to its parent gameobject?

misty glade
#

I've found what I believe to be a reproduceable bug in Unity.. how do I go about finding out if it's a known issue (I've googled, no avail) and if not, reporting it..?

soft hawk
soft hawk
#

@tough tulip i assume thats for a canvas?

#

I'm trying to use UI elements

tough tulip
#

yes. do you need one for new UI Toolkit?

#

oh i see

soft hawk
#

best solution I found so far was to adjust the the position of the root visual object

tough tulip
#

try to find its counterpart for UI Toolkit. you should find it easily.
i dont have experience or have used the new UI sorry!

soft hawk
#

๐Ÿ™‚ thanks anyways

urban warren
soft hawk
#

Well I have UI panels that are overlays for the gameboards

#

I didn't want to make 2 different UI panels that were exactly the same except for their position

#

so I adjusted the root element position on each one by code

urban warren
#

Make a UI panel with its root element positioning absolute and left,right,top,bottom set to 0. Then have an element with positioning absolute which is the overlay. You then position that element instead.