#archived-code-general

1 messages · Page 218 of 1

hard viper
#

floating point precision issues would kick in around 10^-16

pulsar holly
#

How can I make an object stop falling with OnTriggerEnter?

hard viper
#

ok, I think I figured it out. it's like the physics system makes the collider smaller by 0.015 exactly before it does .Cast. Why 0.015? No clue

hard viper
pulsar holly
#

I'm making a falling block game and I need the pieces to stop falling when they're touching.

dusky lake
pulsar holly
#

How do I do that?

hard viper
#

there's a lot to unpack here

dusky lake
#

How are you currently making them fall?

hard viper
#

you need to first understand how you are making your blocks move

pulsar holly
lean sail
pulsar holly
#

IDE?

dusky lake
#

!ide

tawny elkBOT
pulsar holly
#

Yes

#

I'm using Visual Studio

lean sail
#

hit ctrl k ctrl e real quick to fix those indents. To answer your question though, just use a bool to store if it hit something in OnTriggerEnter. Set it to true on there, return early from update if that bool is true.

jolly thistle
#

Hello!

I have a game that has users find words and it fills them in to a larger story as you collect them. Running into incongruences when I make a WebGL build. In the build, the IndexOf method always returns -1, meaning it can't find any instances of the word in the larger story. In the editor, it can find them and my function works. I assume it has something to do with asynchronous loading within WebGL, but I'm not sure how to solve that if that is the case.

TextAsset raw;

string[] wordlist;

void Awake(){

    wordlist = raw.ToString().ToLower().Split(" ");

}

void FindWord(string word){

    if(wordlist.Contains(word)){

         int index = wordlist.IndexOf(word);

    }

}

FindWord is called from a different script in the Start function. the TextAsset is preloaded.
Whats weird is that wordlist.Cointains() returns true and IndexOf returns -1. If it exists within the list, it must have an index, no?

Thank you for reading. Any solutions are advice would be appreciated.

cosmic rain
jolly thistle
#

trying that now. I think i've diagnosed the problem pretty closely. Is there some alternative to IndexOf I could use?

#

yeah, same issue going through w debugger

cosmic rain
plush junco
#

Can anyone help me with something in blueprint?

cosmic rain
cosmic rain
somber nacelle
plush junco
#

thank you

eternal summit
#

Hello
I am working on a script that has parallel arrays of different data types (an in-scene gameobject reference and an int value that goes with it)
I'm kinda worried that this will make it hard to manage since I'll be changing them a lot in the inspector on many instances (easy to accidently delete from one and not the other)

I'm thinking maybe a class that just stores these values would be better? Or is there a simpler way to store them in a way that keeps them together

dusky lake
eternal summit
#

Thanks
Ngl I don't really remember the difference between structs and classes
I don't think I've ever used them since learning about them 😅

dusky lake
#

Struct is a value type, class is a reference type

#

Difference Between Struct and Class in C#
One major difference between structs and classes is that structs are value types, while classes are reference types. This means that structs are copied by value when they are passed around, while classes are copied by reference.

jolly thistle
cosmic rain
jolly thistle
cosmic rain
#

In this case I don't see why that should work at all

#

When you search for index of a, it wouldn't find, since Hamlet is not equal to a.

#

Aaah

jolly thistle
#

IndexOf() finds the index of the occurance in a list

cosmic rain
#

Okay, so the list contains all the words from the book?

jolly thistle
#

yes

cosmic rain
#

And in the debugger you can see the index of the first a?

jolly thistle
#

Yes. and in the editor it finds and returns it correctly. Just in the build it returns -1 for some reaosn

cosmic rain
#

Are you debugging the build?

jolly thistle
#

Yes

#

it gives me the error "startIndex cannot be a negative number" because its trying to find -1 in the list when I use it

cosmic rain
#

So what index does the a have in the list when you look at it in the debugger?

jolly thistle
#

-1 in the build

#

but in the editor its like 39 or something

cosmic rain
#

No, when you look at the list in the debugger...

#

You said that you have found the a in the list manually in the debugger, right?

jolly thistle
#

Yes

cosmic rain
#

Can you take a screenshot of it?

jolly thistle
#

yes give me a moment

quartz folio
#

Your above code isn't really debuggable, because the local variable is never used

#

your method (as previously sent), effectively does nothing

dusky lake
#

That sounds a lot like the issue is somewhere else and its coincidence 😄

#

Well.. can you post the BombSpell.cs / Spell.cs?

jolly thistle
jolly thistle
quartz folio
jolly thistle
#

It's just one script. It is called outside but the issue is in a difference between the editor and the WebGL build

#

I really don't know how to solve this problem because it seems like the IndexOf method just isnt working.

quartz folio
#
void FindWord(string word){

    if(wordlist.Contains(word)){

         int index = wordlist.IndexOf(word);

    }

}

index is a local variable, and outside of that if statement it does not exist

somber nacelle
jolly thistle
#

Okay. Real code coming up

quartz folio
#

This class is in its own file, yeah?

dusky lake
#

Then we need to see your BombSpell and Spell classes, only thing i can imagine is if you work with some static stuff that overrides each other

somber nacelle
#

!code

tawny elkBOT
dusky lake
#

Yeah, but please post code as described above in the future

I cannot see anything apparent directly, I also have no knowledge of fishnet which complicates it 😄

cosmic rain
somber nacelle
#

which object's Awake method is not running?

dusky lake
#

Well you are using the fishnet NetworkBehaviour, so there might be more things going on

dusky lake
quartz folio
cosmic rain
somber nacelle
#

in what way exactly is it not working?

#

please provide actual details about what exactly is not working and how you have confirmed it is not

#

just saying something is "not working" is not providing actual details

jolly thistle
# somber nacelle you should share your *actual* code without removing things you think may not be...

Here is my actual function, with all the bits and bobs:

        string final = incompletestring; // text file of underscores-- missing words that will be replaced when found
        foreach (string word in wordlist)
        {
            string temp = rawlower; //full string with all lowercase letters
            int startPoint = 0;
            int i = 0;
            while (temp != null && temp.Contains(word) && i<200) {
                int index = temp.IndexOf(word);
                int finalindex = index + startPoint; //index in complete string, starting from current iteration
                string currentword = raw.Substring(finalindex, word.Length); // word with proper capitalization
                bool isWord = true;
                if (temp[index + word.Length] != ' ' || temp[index - 1] != ' ') //check if its contained within a word
                {
                    isWord = false;
                }
                if (isWord)
                {
                    if (".,-:;".Contains(temp[index + word.Length])) // check if word ends with punctuation
                    {
                        currentword += temp[index + word.Length]; //add any punctuation
                    }
                    wordsFound++;
                    final = final.Remove(finalindex, currentword.Length).Insert(finalindex, currentword); //replace underscores with word
                }
                temp = temp.Remove(0, index + currentword.Length); // remove all text up to that point, to find next index
                startPoint += index + currentword.Length; // set starting index offset
                i++; //iterator to break infinite loops (of which i have not solved)
            }
        }
        return final;
}```
somber nacelle
#

i don't see any logs in Awake.

#

and do you have any errors in the console? because nothing you've shown so far would prevent an Awake message from being received

#

and your log is conveniently on the line right after something that could potentially throw an exception

#

make sure you are scrolling to the top of your console and viewing the first errors that appear

quartz folio
jolly thistle
#

thats why i simplified haha 🙃

cosmic rain
#

Were you actually resting the simplified version though?

jolly thistle
#

Yes, i ran that to try and simplify the problem to figure out how to fix it, and it didnt work both times. So i used the simple version to ask my question

cosmic rain
jolly thistle
#

Not my VSCode debugger because it is a WebGL build.

cosmic rain
#

I'm not 100% sure, but it should be possible to connect the debugger to a WebGL build.

#

Nevermind. It seems like it's not possible.

jolly thistle
#

I tried, when I googled it said it was impossible

#

yes

somber nacelle
#

well creating another type that also inherits from the same base type as another wouldn't cause any issues with the other object receiving an Awake message (unless it's due to the networking framework you are using somehow).
if the object is being instantiated disabled then its Awake will not be run. that's like the only thing that would prevent a component's Awake method from being called

cosmic rain
cosmic rain
# jolly thistle I tried, when I googled it said it was impossible

One thing that I can think of is that you're hitting some limitation with playerprefs in the WebGL build. Though, if that was the case Contains would also return false. In fact I feel like it might be returning false and you just don't confirm it thoroughly.
I really doubt there's a bug with index of. If Contains returns true, there's no way IndexOf would return -1.🤔

jolly thistle
jolly thistle
quartz folio
#

Contains is an ordinal search in a collection

#

IndexOf uses CurrentCulture by default; which is why it's recommended to always specify the culture

jolly thistle
#

Hoolllyy shit. Wouldve taken me years to find that. C# sucks sometimes. Thank you so much.

#

You have singlehandedly saved my project from dying hahahaha

#

serious wizard shit

quartz folio
#

strings suck, there's a lot of gotchas in every programming language

cosmic rain
quartz folio
#

String.Contains does

#

this is just an array check, and so it's checking using equality

#

Oh wait, that is String.Contains

#

I have no idea lolLooks like it is ordinal

cosmic rain
#

No, in the minimal example they used Array.Contains I think.

quartz folio
#

This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
Huh, C# is fucky

#

To perform a culture-sensitive or ordinal case-insensitive comparison:

On .NET Framework: Create a custom method. The following example illustrates one such approach. It defines a String extension method that includes a StringComparison parameter and indicates whether a string contains a substring when using the specified form of string comparison.

#

They just didn't have culture implemented in this version of .NET for Contains at all

jolly thistle
#

Seriously silly

#

i had a headache all day racking my brain trying to figure out what the problem was

bold wraith
#

does anyone know how to work a level changing script?

vagrant blade
#

That's generic in so many ways. There is no one way to "work" something gameplay specific.

#

You need to show your work and issues.

naive swallow
bold wraith
#

i have a few scripts for it

#

it doesn't seem to work though when I add a trigger and script add on to the object

lean sail
tawny elkBOT
bold wraith
lean sail
#

Please stop this is the worst way you could be posting code

bold wraith
#

oh how then?

#

I thought screen shots were fine.

rigid island
#

is not

lean sail
#

#854851968446365696 and also look just slightly up in this conversation. I linked the code command

bold wraith
#

!code

tawny elkBOT
bold wraith
#

ok one moment ill use this site

#

all these codes for scene/level changing don't work in the unity part, it doesn't show console problems though or visual studio problems though

rigid island
#

you haven't said if its 2D or 3D?

bold wraith
#

im not sure how to function one to start it for my character to slide across to change it

#

its 3d

rigid island
#

do you have at least 1 rigidbody

lean sail
bold wraith
#

my object has no rigid body

rigid island
lean sail
bold wraith
#

I am not sure, how to function the object that starts a level changing trigger, basically when its open I don't know what is the right format to operate it in game mode to continue to the next scene.

#

ok i'll add one rigit body to the 3d graphic object

rigid island
bold wraith
#

yes, a cube

rigid island
bold wraith
#

one moment

rigid island
#

also looks like one of the collider is prob not trigger

#

if camera is parented to capsule and capsule has rigidbody might wanna lock that rigidbody

#

or better, use Cinemachine and unparent cam

bold wraith
#

the capsule has a rigid body

#

the object of cube has a rigid body, a script. a box collider,

rigid island
#

if capsule has rigidbody cube doesn't really need one

lean sail
bold wraith
#

ok so the scripts are fine?

lean sail
#

fine would be a stretch, there really isnt much that can be fundamentally wrong though

bold wraith
#

i removed the rigid body from the object of level changing

lean sail
#

this is definitely a #💻┃code-beginner issue for the future. go through that link still and see why its not working. Id suggest you even just test this on basic cubes so you understand the cases for when you should receive a trigger message

rigid island
bold wraith
#

of added to box collider... a trigger?

#

the collider if added a box collider with a trigger checked it disappears

spring creek
#

Probably falls through the ground

bold wraith
#

it has a rigid body

spring creek
bold wraith
#

to keep it maintained on the ground/mass

spring creek
#

Simply NOT having a rigidbody would keep it in one spot

rigid island
#

if this is only a trigger why does it need to be "grounded/mass"

bold wraith
#

one moment

#

ill erase the rigid body from the cube

#

its erased

#

removed

rigid island
#

we don't need a step-by-step

spring creek
bold wraith
#

ok just the box cube is set with a trigger

#

under box collider

#

with a script of GAMEPLAYUICONTROLLER(1)

rigid island
#

why

#

if the trigger script is called nextscene

bold wraith
#

oh thats the one you think works?

rigid island
#

you tell me

lean sail
#

from what you've shown, GameplayUIController does literally nothing by itself. It honestly seems like you dont know what your own scripts do

rigid island
#

you have another one called Portal

#

with OnTrigger

bold wraith
#

ill change it to nextscene

#

and see if it works

#

these scripts i have im new to

#

ok?

rigid island
#

don't just guess youor way through this

#

you should follow a structured course

#

!learn

tawny elkBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

bold wraith
#

im asking here for pro help

rigid island
#

the Pro help would be to go through courses

#

fumbling your way through it will just be confusing

bold wraith
#

this is ridiculous

#

one moment

lean sail
bold wraith
#

this is worse than a devils act around an angel

#

i put in about a week or two trying to do this

spring creek
bold wraith
#

lol

#

a joke

lean sail
spring creek
#

You've been getting like 2/3 on one help for free for over an hour...

bold wraith
#

ill try some other time if you guys are complaining about my code level

#

dont bother me if you dont know how to do this

#

good bye

lean sail
#

I guarantee everyone who responded to you could have it working in 15 seconds. You simply dont understand your own code, and what we are saying to you

spring creek
spring creek
knotty sun
#

post to a paste site please !code

tawny elkBOT
finite swift
#

I'm trying to make it so that when falling my player does its falling animation, however I'm having troubel with the animation getting stuck on the jump animation, and not switching from jump to falling. Whats weird is the jump animation does not have this problem with switching between anything else. After a while of bug testing it seems like the issue is happening due to the IEnumerator JumpCooldown()
But for the life of me, I can not figure it out, if anyone has any ideas let me know. (If needed I can also post SS of the animator tab)
https://paste.ofcode.org/vhrKNrp9SQs8qi5RQEKjxW

finite swift
#

I'm so sorry, I worked on this for like 4 hours, and as soon as I figure i need to ask, I find the problem, I had for whatever reason just never switched the IsFalling to true instead of false (the default) I think I need to go to bed haha

knotty sun
#

yep, line 117 should be using Falling not true

#

and you dont need the surrounding if

dawn nebula
#

Do you guys typically use abstract classes or interfaces?

#

Thinking about dependency injection within Unity.

#

Interfaces are preferred but don't appear in the inspector.
Abstract classes do but you obviously can't inherit off of multiple.

lean sail
dawn nebula
lean sail
vague tundra
#

This might end up being a pretty basic question but:
In the attached situation, CardZoneController is an abstract class. MonsterZoneController extends CardZoneController. ConcatNoMutate expects a List<T>, where in this case T is CardZoneController.
Where have I gone wrong here? I expected this to be legal

fervent furnace
#

you can convert T to U does not mean that you can convert List<T> to List<U>
eg int can be converted to long but List<int> is not List<long>

vague tundra
#

Oooh amazing, thank you!

fervent furnace
#

though they are fundamently pointer...

turbid acorn
#

Does anyone else know swift

last island
#

Is there a way, using Unity XR, to check if HMD Rumble is turned on?
Not whether it's capable of HMD Rumble, but whether it's turned on at all.

last island
#

Also what are "channels" exactly?

#

In the InputDevice.SendHapticFeedback() method it expects a "channel". I have set it to 0, but I don't know what a channel is. Is that about what motors to use or is it what HMD to send it to in case there are multiple?

rigid island
turbid acorn
rigid island
#

its not like swift is any better than c# or anything

turbid acorn
rigid island
hard viper
#

we are not going to know about swift here

#

If I have a kinematic RB at position1, and I call MovePosition(position2), where do we get collision callbacks?

#

do we get collision callbacks right after physics update as though we are at position1 or at position2?

#

and is that different for how it would be for a dynamic RB?

steady moat
# hard viper and is that different for how it would be for a dynamic RB?

On the first physics update where the collision is detected, the OnCollisionEnter function is called. During updates where contact is maintained, OnCollisionStay is called and finally, OnCollisionExit indicates that contact has been broken. Trigger colliders call the analogous OnTriggerEnter, OnTriggerStay and OnTriggerExit functions. Note that for 2D physics, there are equivalent functions with 2D appended to the name, eg, OnCollisionEnter2D. Full details of these functions and code samples can be found on the Script Reference page for the MonoBehaviour class.

With normal, non-trigger collisions, there is an additional detail that at least one of the objects involved must have a non-kinematic Rigidbody (ie, Is Kinematic must be switched off). If both objects are kinematic Rigidbodies then OnCollisionEnter, etc, will not be called. With trigger collisions, this restriction doesn’t apply and so both kinematic and non-kinematic Rigidbodies will prompt a call to OnTriggerEnter when they enter a trigger collider.

https://docs.unity3d.com/Manual/CollidersOverview.html

hard viper
#

I see. so OnCollisionEnter would mean position1 was not in contact, and position2 is?

steady moat
steady moat
#

You gonna have the collision whenever the collision happens

hard viper
#

during physics update, we have MovePosition from pos1 to pos2

#

OnCollision give callbacks with contacts etc

#

are these callbacks based on what the state is supposed to be when the rb is at pos2?

steady moat
#

Read the second message

#

I sent

hard viper
#

I understand that, but are the callbacks based on the position after MovePosition?

steady moat
#

Unity moves a Rigidbody in each FixedUpdate call. - Rigidbody.MovePosition moves a Rigidbody and complies with the interpolation settings.

steady moat
#

At least, this is what the documentation says.

#

If you want to be sure, you can easily create a test.

hard viper
#

the documentation doesn’t seem to specify

steady moat
#

It says that the rigidbody will move base on the interpolation settings each fixed update. It also states that the collision event will be called whenever the collision is detected on the physics update

#

In other words, it is possible that it is neither position1 or position2

hard viper
#

so we don’t get the callback now, we would get it next frame

#

if I understand, when I moveposition from pos1 to pos2, and pos2 has contact with wall, that physics update just sets us in motion to pos2. then the NEXT physics update which starts us at pos2 generates contacts for existing at pos2. Is this correct?

steady moat
#

You cannot do Rigidbody.MovePosition and expect to receive a OnCollision event directly after.

hard viper
#

i understand, but the question is if I get it at the end of the upcomping physics update, or the update after the next

steady moat
#

That can be easily tested

hard viper
#

yeah… I feel like the documentation should probably be more specific on that

steady moat
somber nacelle
dusky pelican
#

!code

tawny elkBOT
azure heath
#

Hi, I’ve just learnt about the [System.NonSerialized] tag and was wondering in what situation you would use HideInInspector over NonSerialized on a public variable. Why would you want to serialize a variable but not have it show in the inspector?

somber nacelle
#

you could have some other objects changing that value at edit time like some other component or an editor script but you don't want it to be directly modifiable by the developer

#

or if it is dependent on other values you assign in the inspector but you don't want it to do whatever necessary calculations at runtime it can be assigned to in OnValidate

hard viper
#

NonSerializedField means it just doesn’t get saved to a file period

turbid acorn
hard viper
#

when you have a public field, that usually gets serialized by default. So if you want to make public int currentHealth; you probably really don’t want that sereialized

hard viper
#

whereas a scriptable object might have a field for you to edit: jumpHeight, and then it generates and saves the value of jumpForce based on that value. You would want to HideInInspector jumpForce

hard viper
#

how do 1 way platform effectors work? is it based on velocity, or if overlapping etc?

#

i assume it is “if not overlapping AND hit normal vs effector ref vector angle < arc angle, then don’t ignore. Else ignore.”

hexed carbon
#

kinda outta the blue, but if you were to have a tank with the road wheels as wheel bodies can you have a piece of code auto draw track lengths between them so you have dynamic tracks and suspension?

clever trellis
#

anyone knows what is this?

#

what does the error mean?

#

everything turning black

#

kindly help

rigid island
#

this is not a code question

clever trellis
#

its giving a code errror

#

i thought there's a problem in code, that's why

#

error due to this func:

ashen bough
#

hi, I have a scriptable object that I want to activate or deactivate gameobjects, run functions and activate or deactivate audio sources, for some reason it won't let me assign gameobjects [SerializeField] private UnityEvent onLoadEvents;

somber nacelle
#

assets (like ScriptableObjects) cannot refer to scene objects at edit time, you'd have to subscribe to the event at runtime

ashen bough
#

oh, thanks

cyan mortar
#

So, I'm exeperimenting with 2d effectors to create pass-through platforms with a tilemap. The catch is that you can collide with it from the side. I want no side collisions, and with the default settings, it shouldn't be happening.

hybrid turtle
#

has anyone had difficulty with Zenject dependency injection not working

#

I keep trying to inject a class but to no avail

#

it keeps saying its null

#

however going into a different class and injecting the same class is ok and works

leaden ice
hybrid turtle
#

lol maybe I'll switch it later on its just I use it so extensively that would take me a while to switch

leaden ice
#

I would guess it's more likely a misconfiguration in this particular case than a bug in Zenject

somber nacelle
brittle oyster
#

What's the most efficient way you can pick out any particular range of bits from an int?

#

My current solution is to do a series of shifts and byte casts, not sure if there's a better way

leaden ice
brittle oyster
#

damn

#

what im doin is ugly as hell tho

leaden ice
#

well idk exactly what you're doing

#

since this gives a Span<byte> which probably means it's not allocating an array like BitConverter does

brittle oyster
#

yeah im really trying to avoid memory allocation for this

#

maybe i look into that

simple egret
#

Bitwise-ANDing the number with a specifically crafted one that will extract the desired bits is also an option

somber nacelle
brittle oyster
simple egret
#

"A jumble of data"

#

what

brittle oyster
#

I've stuffed position, uv, and lighting data into a UInt32

simple egret
#

Side-by-side?

brittle oyster
#

i'm just trying to find a way to efficiently cut out portions of that UInt32 corresponding to each piece of data

brittle oyster
simple egret
#

Then multiple AND operations with multiple specially crafted numbers

#

Can't get any more efficient than that, CPUs work with bits, these instructions are literally engraved in them

brittle oyster
#

yeah

#

maybe i do something like that

simple egret
#

You can use your Windows calculator in programmer mode to make these numbers in binary, and convert them to integers, so the code is kept compact

brittle oyster
#

I think I've got a solution in mind, stemming from what you said about AND

#

Just some complication with extracting a range > 8 bits

#

Thanks man

dusky pelican
#

!code

tawny elkBOT
lean sail
hard viper
#

if you need a chunk of X bits with Y bits to the right of it, then you could do:
range = (1 << (x+1)) - 1; // this is a block of x 1’s in a row.
then range << Y gives the result

#

then if you just want the block of bits from the uint, you can take that number & the other number, so it gives a result with everything else to zero.

brittle oyster
#

I'm trying to figure out how that works

simple egret
#
  0011_0010_1101_0011_0101_1001 (your number)
& 0000_0000_0011_1111_1100_0000 (the magic extractor)
= 0000_0000_0001_0011_0100_0000 (the extracted number)
  0000_0000_0000_0000_0100_1101 (shifted 6 bits right => the result)

The shift operation can come before the extraction using &, this changes how the extractor number looks like

leaden ice
brittle oyster
#

You mean split each into its own field?

#

Like a float3 for position, float2 for uv, and so on?

#

Main reason why I'm going thru all this trouble is specifically so I can store each vertexes info into a single UInt32

#

I'm creating a voxel world, so memory can get out of hand really qucik

#

If I was't doing this, I would be expending around 100 bytes per vertex

#

This way I only allocate 4

simple egret
#

A struct of say 2 fields of 4 bytes will be as long as a single number of 8 bytes

hybrid turtle
#

ok question I made a timer on my mac but when I test it on aother laptop it takes forever

simple egret
hybrid turtle
hard viper
#

that << 4 = 00011111110000 (4 zeros to the right now because we just bitshifted it)

#

now if you & with this mask, anything that is not in that range of ones gets (some number & 0), which is zero.

#

and every number within that little block gets &1, which is just itself

#

understand?

#

i didn’t count the zeros on the left, but you get my point

simple egret
# simple egret Plus you can tell the struct how it is laid out in memory (with the `StructLayou...

For example, here's a struct that stores 4 bytes on a single uint, using the manual struct layout:

[StructLayout(LayoutKind.Explicit)]
public struct Sample
{
    [FieldOffset(0)] private uint _value;
    
    [FieldOffset(0)] public byte A;
    [FieldOffset(1)] public byte B;
    [FieldOffset(2)] public byte C;
    [FieldOffset(3)] public byte D;
}

The 4 bytes (A, B, C, D) each have an offset (from the start of the struct in memory) that falls in the range of the uint, an number on 4 bytes.

// uint value
0000_0000_0000_0000_0000_0000_0000_0000
    A    |    B    |    C    |    D

So you can pack your own data into a single value, and still get a fairly high-level representation of it with the individual public fields!

brittle oyster
brittle oyster
#

Will have to look into that

leaden ice
#

nvm answered

brittle oyster
#

I’m using a custom mesh layout

#

Yeah

brittle oyster
hybrid turtle
#

ok im confused my program definitely running differently

#

on my windows pc and my mac

#

its the same script but for some reason it works on the mac system but does not work on the windows

leaden ice
#

likely you have either:

  • framerate dependent code
    or
  • code which depends on execution order of scripts
#

neither of which is guaranteed between platforms

hybrid turtle
#

like can I share my code

leaden ice
#

!code

tawny elkBOT
hybrid turtle
#

ok here it is

leaden ice
#

The other thing you need to do is explain what exactly is going wrong with the script

#

What do you expect to happen anbd what's happening instead

hybrid turtle
#

ok this should be better sorry

leaden ice
#

This is the same thing

#

don't upload a file to discord

#

share as per the guidelines above

simple egret
#

Paste the link hastebin gives you when you hit Save

hybrid turtle
#

ok ok thank you

#

there we go

#

sorry guys and thanks again

leaden ice
#

alright now can you explain what's going wrong with it?

hybrid turtle
#

yeah of course so basically on my mac this works correctly and when holding the button 2 down for timerDuration it will countdown then fade into another scene but as soon as you are on the other scene and let go of 2 it fades back

#

all I did was load the scene additively to begin with and created an empty gameObject to hold this script attached to it

#

this behaviour works fine on my mac however it takes way longer to load on my windows comp and it does not fade back properly

brittle oyster
hybrid turtle
#

on the windows as everything works on my mac

#

I tried to avoid using Time.deltaTime as to avoid issues with framerates and opted to just use the yield new WaitForSeconds approach which slightly fixed it

leaden ice
#

I'm trying to figure out why there's a separate "countdown" and "fade" coroutine

hybrid turtle
#

however I suspect there is something wrong with my if and else if in the Control Timer

leaden ice
#

and honestly not sure why the input handling stuff needs to be a coroutine

hybrid turtle
#

I wanted to abstract fade and Refade into one but i kept having issues with the alpha

#

and not really should I just move them into update

#

wont make much a diff at all

#

yeah may be an issue with the coroutine after all in this case

#

when I move to update I get this error thrown

#
UnityEngine.Rendering.DebugManager.UpdateActions () (at Library/PackageCache/com.unity.render-pipelines.core@7.7.1/Runtime/Debugging/DebugManager.Actions.cs:176)
UnityEngine.Rendering.DebugUpdater.Update () (at Library/PackageCache/com.unity.render-pipelines.core@7.7.1/Runtime/Debugging/DebugUpdater.cs:18)```
leaden ice
#

That doesn't seem related to your script

hybrid turtle
#

ill check the other parts then but it was thrown when I moved the things to update

sweet raft
#

If I script is added to a GameObject during runtime, are Awake and Start still called on that script?

hybrid turtle
#

@leaden ice I figured out the issue is the timer coroutine

somber nacelle
hybrid turtle
#

howeveer how do I make a framerate independent timer without a coroutine

spring creek
sweet raft
hybrid turtle
spring creek
hybrid turtle
#

thank you much easier than using a coroutine

hybrid turtle
#

however even with Mathf.Approx it not saying it ever reached duration

spring creek
#

You want something like this

private void Update()
{
  currentTime += Time.deltaTime;
  if (currentTime >= thresholdTime)
  {
    currentTime -= thresholdTime;
    //do whatever
  }
}

Done on my phone haha

hybrid turtle
#

yeah ofc i think that better

dusk apex
#

Could probably do it with time stamps as well

hybrid turtle
#

how would I do that?

dusk apex
#

Instead of accumulating deltas, you'd set the next expected threshold time when threshold time is met.

#

If Time.time > threshold, threshold = Time.time + next and do other stuff

hard viper
#

woot. physics engine is finally coming along

tawny elkBOT
hybrid turtle
#

hi can anyone take a look at this code because I am still having issues with it running just fine on my mac however not at all on my windows pc

#

yeah im like real confused why it working

#

on my mac but not at all on the windows pc after build

heady iris
#

perhaps you need to add some Debug.Log statements so that you can see what is and is not happening

hybrid turtle
#

yeah I have been logging the time and that it actually does go into the statements

#

my only supposition is the Mathf.Approximately

#

that may be system dependent

#

because to me after logging everything looked ok

hard viper
#

what is the point of Rigidbody interpolation with a kinematic rigidbody?

#

isn't MovePosition supposed to figure out how to make it smooth anyway?

leaden ice
#

aka not every frame

#

so it needs interpolation too

hybrid turtle
#

ok so the transition fades in and out properly in the unity inspector when played on my mac and takes the right amount of time until it fades

#

however when ran on windows pc it takes way longer doesn't fade nearly as nicely and then on the fade out becomes stuck

#

id share a screenrecoridng but it too large

#

any help appreciated for sure idk why it doing that

cosmic rain
hybrid turtle
#

ok ok Ill send all the logs Ive put quite a few before but everything seemed ok

#

here are the logs I did with each case

#

when nothing is done it is in the rest timer case so timer should still be 0 which is correct

#

as long as two is pressed it's in the press-down case

#

when it reaches about 5 seconds the fade time it goes into the fade case

#

then once two is pressed down it goes into the refade case

#

this is all correct behaviour but for some reason it doesn't on the pc

cosmic rain
#

That's fine, but what about the coroutines?

hybrid turtle
#

I put one inside each of the coroutines tracking the elapsed time and see that it does count up to the fade duration which is 1 second

cosmic rain
hybrid turtle
#

yeah on the PC it does not even fade out

#

like this is the output on the console

#

when I run the log statements showing that elpasedTime of each fade is going to 1

#

like im only running the built version on the pc

cosmic rain
hybrid turtle
#

nope this is from the mac im running Unity on

#

on the mac I export a PC build

cosmic rain
#

Are any logs that you've seen or shared from PC?

hybrid turtle
#

then it doesn't work on the pc

#

nope there are no logs from the pc I wouldn't know how to get live logs while the build is running

cosmic rain
#

So basically the whole conversation so far was pointless

hybrid turtle
#

😦

cosmic rain
#

What's the point in the logs from where it does work..?

tawny elkBOT
#
📝 Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

hard viper
hybrid turtle
#

ok thank you sorry and ill do that rn

hard viper
#

i guess I’m not sure what goes into motion via interpolation, because I assumed the rb was just moving along on its path each real frame

#

maybe I can simplify my question; on a given Update() call, assume I can work out the position this rb is supposed to be at. Do I just… set rb.position?

somber nacelle
#

rigidbodies only move on the physics update. interpolation just predicts where the transform should be and updates its position each frame. but then the physics update happens and the transforms will by synced to the rigidbody's actual position

leaden ice
#

but interpolation doesn't really work with manual Simulate calls AFAIK in any case

hard viper
#

auto interpolation does not work, so I’m trying to figure out manual interpolation

hard viper
#

at this point, i feel like the main lesson i’ve learned is to never move a transform when I have a rigidbody lol. hence why I’m looking for confirmation before a long quest of checking for bugs

cosmic rain
#

I'm not sure it would be that simple. Moving the transform, might sync to the rb, so it would get moved as well eventually. Which would break things.

#

Unity probably moves it in some way that does not affect the rb behind the scenes.

somber nacelle
#

yeah, this building a physics "engine" on top of another physics engine is going to cause some weird issues like that. since you cannot control the internal state of the rigidbody you can't really do interpolation like the rb would

cosmic rain
#

I don't know if disabling Phywics.autoSyncTranaforms might help with this. Anyways, trying to interfere with how the physics engine works like that is not a great idea imho.

#

From the description it sounds like it might. But it's not clear wether it's enabled or disabled by default.

hybrid turtle
#

ok ngl Im having trouble locating %LOCALAPPDATA%\Unity\Editor\Editor.log on my windows pc i went into the folder where the build is stored and enabled hidden files and only saw Graffiti+_Data which i went into but cant find that file

somber nacelle
#

you should be looking for the player log not the editor log. but you can literally just copy paste that into the address bar to open that log file

hybrid turtle
#

lol ok ill do thar

#

ye i copied and pasted

#

nothing yet

#

like it says no resultds

somber nacelle
#

you paste it into the address bar of your file explorer. but that's still the wrong log file

#

and the one you should be looking for will have a path dependent on your project name and company name

hybrid turtle
#

yeah

#

i pasted it into the address bar of file explorer

cosmic rain
#

There are other ways to do it too:

  • connect your ide to the game (even possible remotely)
  • connect the editor to the game(should be possible remotely as well)
somber nacelle
hybrid turtle
#

ok yeah i dont have unity editor on my laptop

#

and i went searching for player log directory but couldnt find one

somber nacelle
#

where did you look?

hybrid turtle
#

_EXECNAME_Data_\output_log.txt

#

i got this actually

somber nacelle
#

that is for unity 5. are you using unity 5?

hybrid turtle
#

using unity 2019.4

somber nacelle
#

then click the link the bot gives for the !logs documenation

tawny elkBOT
#
📝 Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

hybrid turtle
#

I see it now

#

thanks @somber nacelle

#

ill give it a shot

#

yeah I just see a whole bunch of .dll files

#

and found the app data

#

but cant find localLow

somber nacelle
#

copy and paste this into the address bar: %userprofile%/AppData/LocalLow

hybrid turtle
#

ok ok

#

thank you

#

so so much again

#

pasted

#

no results found

somber nacelle
#

sounds like you're putting it in the search bar not the address bar

hybrid turtle
#

ok i tried the address bar nothing

#

i put the exact thing in

#

i found this so far user\Desktop\App\Data

#

but in data no localLow to be found

#

i searched all subdirectories as well

somber nacelle
#

yeah you're obviously not going to find it if you search in the wrong location

hybrid turtle
#

yeah 😦

#

idk what else to do though

#

should I ask another dev or smth

somber nacelle
#

screenshot what you see when you copy/paste %userprofile%/AppData/LocalLow into the address bar of your file explorer

hybrid turtle
#

yeah ofc

#

ok my dumbass

#

i found it but there are two folders with the company name

#

idk ill check both

rigid island
#

how many projects you made?

somber nacelle
#

it depends on what you've set in the Player Settings in your project settings

#

if you did not manually set it then it would be DefaultCompany

hybrid turtle
#

yeah bruh idk what they set it to this thing been made over 10 years its been reewritten at least idk how many times

#

ill check what the recent dude put fir it

somber nacelle
#

is this not for your own game?

hybrid turtle
#

nah

#

im hired to make small changes

#

just a uni student intern 😦

somber nacelle
hybrid turtle
#

yeah i do have access to it

somber nacelle
#

then just look . . .

hybrid turtle
#

yeah

#

ok i found it

#

got into the logs

#

thanks again guys for the help really appreciate it

cosmic rain
#

Might be useful to learn to connect the debugger next.

hybrid turtle
#

yeah I have it connected on my mac

#

but i want to do the remote to the pc

#

that would help a lot

cosmic rain
#

If they're on the same local network, you just need to "attach to process", change connection type to remote and type in the IP of the PC. Then just select the process and connect.

#

Assuming you're using visual studio

hybrid turtle
#

yeah im on visual studio

dire marlin
#

i'm baking a nav mesh path at the start of the game for my randomly generated dungeon game but for some reason it gives out errors for different meshes in the rooms like lockers. lights, etc.

#

how can i fix?>

leaden ice
#

you'd need a reference to the specific instance of this class you want to use the event from
note that each instance of the class has its own event.

cosmic rain
dire marlin
#

ohhh ok thank you

leaden ice
#

I don't think what you're doing makes much sense especially if this is a MonoBehaviour

#

you might be able to get away with it on a ScriptableObject

#

You'd have to get a reference to the object which likely means Resources.Load or via Addressables

rigid island
leaden ice
#

is the code running? Use Debug.Log to check

#

If the code is running then the event is firing (assuming you put a log in the correct place)

ashen yoke
#

want to point out that while it may have fixed it, the conclusion you drawn may be incorrect

#

you need to look at specifics of what exactly was null, because if it were true that events in start were failing it would affect everything else in the engine

spring creek
#

Start is not the first frame though. It would happen as early as after all Awakes of objects that exist before the scene starts have run

ashen yoke
#

or at any point during runtime

spring creek
#

Tried to fix it and I made it more confusing haha

gilded grove
somber nacelle
#

are you actually deserializing with newtonsoft json? because that should work just fine if you are

gilded grove
#

Ah, I guess I can't use JsonUtility with it... I'll try again, thanks

cosmic rain
somber nacelle
dusky lake
somber nacelle
gilded grove
#

I'm just doing it wrong - I got it from the package manager so it should be [edit] okay

#

I'll take a look again tomorrow, this was a frustration ask, thanks all

somber nacelle
#

the package manager version is the right one to use with unity

gilded grove
#

sounds good, thanks boxfriend

dusky lake
#

is there a unity registry one now?

cosmic rain
gilded grove
#

sorry edit: shouldn't be an issue via package manager

#

again tired

somber nacelle
dusky lake
#

json, newtonsoft, gives nothing 😄

leaden ice
#

it's not going to show up

hollow inlet
#

yo is there a way to get all prefab variants of a prefab? I'm tryna spawn in a randomly selected prefab based on a gameObject

leaden ice
#

you just have to add by name

#

com.unity.nuget.newtonsoft-json

somber nacelle
dusky lake
#

Ahh alright, thats why I asked if they now have it in the registry

leaden ice
#

but it should be there by default iirc yeah

dusky lake
somber nacelle
#

yeah should be installed by default

dusky lake
somber nacelle
#

it's installed by default in 2023 which is the version i'm using. and i'm fairly sure i read it should be there by default in 2022

dusky lake
#

havent removed any, just added

cosmic rain
#

You have "in project" selected.

dusky lake
#

Yes, we are talking about newtonsoft json being installed by default

gilded grove
#

JsonUtility is default, you have to search for newtonsoft in the pacakge: com.unity.nuget.newtonsoft-json@3.0

dusky lake
#

which would make it be "in project"

ashen yoke
#

com.unity.nuget.newtonsoft-json@3.2 just add to manifest

dusky lake
somber nacelle
#

not really, most of the more obvious stuff that was changed in 2023 was already marked as obsolete in 2022 or had warnings.
it's finally got some nice async features though which is the primary reason i'm using it for my current project

somber nacelle
#

also i just found out that newtonsoft was probably installed as a dependency for one of the unity packages i installed so it may not even be a default package 🤷‍♂️

ashen yoke
#

the bigger the project the more the likelyhood of finding edge cases and bugs in new versions

dusky lake
ashen yoke
#

🎲

somber nacelle
#

i swear i read somewhere that it should be installed by default in 2022+ though, but it's been so long that i cannot remember where i had seen that 🤷‍♂️

safe wyvern
#

I am currently working on an FPS controller that uses a list of Vector2's to offset a raycast's direction to give the weapons predictable recoil patterns like in counter strike, How would I add an offset to a transform.forward vector that works consistently?

My vector2 contains the X Offset and Y Offset, that would change the vector3 directions X and Y

leaden ice
#

rotation angles?

ashen yoke
#

or just transform the vector itself

#

so if point is (0.5, 0.25, 0f) + (0,0,1) the result after transformation should be a point next to your forward vector

waxen burrow
#

this one seems like a stretch but I figured I'd ask... Is there a way to get a refrence to an asset that you right clicked and created a new asset with. In my case my attack system requires a SO and AOC for each attack animation. While it allows me to make some cool combos and things it sucks to make new attacks. Would there be a way for me to make a system where I could right click on an animation clip, select an item like "create attack" and automatically have the SO and AOC made for me? So back to the question is there a way to get a reference to an object that was 'right clicked' and a create asset menu item was selected?

ashen yoke
#

yes

#

[MenuItem("Assets/My Method")]
for context menu
in the method

foreach (var item in Selection.objects)
{
    ...
}
waxen burrow
#

would you advise that I do that in the SO to be created or keep it in a seperate script?

ashen yoke
#

whatever is more convenient, this is editor code so either keep it in any Editor folder or guard with #if UNITY_EDITOR #endif

#

best would be Editor/Utilities/CreateAttackFromAnimClip.cs

waxen burrow
#

gotcha

#

thank you so much!

swift falcon
#

Anyone know how I can reset the prefab editing scene via code?

ashen yoke
#

what do you mean by reset?

swift falcon
swift falcon
#

I'll have a look, thanks

ashen yoke
#

there should be PrefabStage

#

and its utility there as well

swift falcon
#

I've been using that but I don't see how I reset the prefab using it

ashen yoke
#

you want to cancel all changes?

#

just close without saving and reopen

swift falcon
#

Okay that's the issue I have I guess, I try to open it when it's already open and it just causes my code to spam new assets in it. How do I close it?

swift falcon
#

mzdunkPrayge Thank you

safe wyvern
soft shard
jagged pendant
#

Hello. I am making an online game, but the problem I encountered is that the reloading domain is repeated endlessly and never ends.

dire marlin
#

hey guys i am developing a game but when i share a build of it to my friends, their computers detect it as a virus. i'm not too sure if it happens with any other games but its quite weird. any way to fix?

lean sail
hidden parrot
#

Quick architecture question. Got a system where when the player clicks, if they click on an interactable object, it interacts with the object with an interface. If it's not interactable, and the player has something in their hand, it uses that item instead, with interfaces again. Is there any way to do this without having the player aiming/click manager be dependent on the interaction systems? I'd like to preserve event based architecture as long as I can.

hidden parrot
#

The click manager isn't dependent right now, it's just running an event to the interaction systems

#

I'd like to keep that if possible, but I don't (ideally) want a dependency on the player item use system to the player interaction system

cosmic rain
#

Could write some kind of event consumer system.

hidden parrot
#

Yeah that's what I was thinking, event that passes from system to system and if a system can use it, it eats the event and stops passing it on.

cosmic rain
#

The game/input manager would dispatch the events to all subscribers as long as they don't consume the event.

hidden parrot
#

Sounds good.

muted sundial
#

Good Morning!
Im doing an multiplayer game with Server, Host and Client Mode (Like Ark or Conan).
i Found some problem with scene management, i start an server in one computer, and trying to conect from another
conection works perfectly but scene managemente needs change logic...
when i connect server and client change scene to same...
i need each client play in our scene but one client can travel to other player scene too
i dont know how to do it ... anyone can help me with some logic, maybe ?

cosmic rain
hidden parrot
#

Priority system and event consumer will work, tysm

cosmic rain
swift falcon
#

Hey

#

I've been coding a game

#

But I need some help figuring out how to store variables in a neat way

#

Across sprites

#

Because all the ways I've been using

#

Are quite clunky

safe wyvern
scarlet viper
#

any way to change layer of all gameobjects in gameobject's tree (children) other than go.layer=xxx in a loop?

fervent furnace
#

i think no, you need to use recursive way (or get all the transforms)

muted sundial
steady moat
# muted sundial Good Morning! Im doing an multiplayer game with Server, Host and Client Mode (L...

You can only have 1 scene active (You can have additive, but they will interfere one with an other) at a time in a server. You either prevent player from going to a new scene alone or you have two server. You could also make things such as you can load all scene additively. This way the server could have multiple scene open. However, you gotta be careful about the fact that each scene could overlap.

dawn sundial
#

Hi, any ideas on how to avoid enums that are used across multiple classes to do some logic based on the enum value?
Imagine scenario:

  • you have a Weapon.cs script that contains WeaponType enum
  • using Raycast you hit IDamageable object, let's say Enemy.cs
  • you call OnHit method inside the Weapon.cs on that IDamageable object
  • the OnHit method inside Enemy.cs has input parameter WeaponType and based on what value from this enum is there it spawns decal (Pistol = Standard Decal; Rocket launcher = Huge Decal).

I'm looking for any feedback, advice, etc.
Even though this works fine it always feels a bit clunky when adding new value to the enum and then trying to find out each class that uses such enum to provide new logic there.
Thanks.

leaden ice
#

or maybe wrap up all the info you need as like:

public struct HitDetails {
  public float damage;
  public Texture decal;
  public float knockbackForce;
}``` and pass _that_ in as a parameter
dawn sundial
#

That would work if you knew what are you hitting, but the Weapon doesn't know that. Hence the interface IDamagable.Onhit()

leaden ice
#

why does it matter what you're hitting?

dawn sundial
#

Wall vs human flesh = different decal.

leaden ice
#

I thought it was the weapon that decided the decal

dawn sundial
#

Well, the weapon tells whether it is a pistol or explosive (rocket launcher, grenade).

#

If pistol - wall makes just small hole, flesh small red hole.
If explosive - wall makes burnt black area, flesh also burnt black area.

leaden ice
#

and the thing being hit can have a mapping of weapon type or damage type to the decals it needs

#

you can use a Dictionary instead of a switch if you want

dawn sundial
#

sounds like a good idea

somber tapir
#

I'd make the decal into a separate script that you can then pass via parameter

dawn sundial
#

could you tell me more about the dicitonary?

#

I assume some static Dictionary <WeaponType, Decal Texture>?

muted sundial
steady moat
#

I do not think there is any loading screen

muted sundial
steady moat
hard viper
#

As I build my physics engine, I’m getting to refactoring code that allows some entities to stay grounded (so they can move along slopes).

Previously with dynamicRBs: At start of FixedUpdate, do a logic check to see if we should try to snap to a floor. If true, ground check down, and if we hit, force us down and keep knowledge of slope normal. Then when evaluating horizontal movement, add force calculated to be along the slope.

I’m wondering if there is a smarter way to do this now that I have a semi-working pseudo physics engine. To try to keep grounded movement along a slope.

steady moat
#

Having work on a Survival Multiplayer games with dedicated server, we used a single scene for everything. That being said, it was more inline with ARK/Conan

hard viper
#

Are there any suggestions for maintaining ground connection along slopes?

muted sundial
steady moat
#

The server can load everything that is close to a player

muted sundial
#

and its moves with players

steady moat
frozen mesa
#

hi everybody i need help i have my prefab and i have attatched my script and in that script i want to put a reference in my public GameObject and my another script but if i try to do so it says Type mismatch. anybody knows how to fix it?

leaden ice
frozen mesa
leaden ice
#

what are you trying to drag from where to where

fervent furnace
#

is the prefab in file try to reference gameobject on scene?

frozen mesa
#

from my assets

leaden ice
frozen mesa
#

ok

leaden ice
#

sounds like whatever you trried to drag was not a GameObject

frozen mesa
#

here when i try to attatch the shooting script sorry for making it confusing now i want to drag the shooting script in there but it says this

leaden ice
#

so now the type is a mismatch

#

But - why is it called "Shooting script"? Did you try to drag a script in there?

frozen mesa
#

i want to drag an object with the shooting script

#

look

leaden ice
#

ok so this is already diverging from what you said before

#

which was "the script have a public GameObject in it"

#

So please share screenshots and code and all relevant details

#

show the object you are trying to drag in here

frozen mesa
#

this is the thing i want to drag in there (it have the shooting script attatched to it)

leaden ice
#

prefabs cannot reference objects in scenes

frozen mesa
#

oh

frozen mesa
sick mural
#

Hey guys ^^
Anyone know how to make something similar to math.distance but with quaternions? I need to know if the rotation reached it's target, but I'll probably never get the exact value, so I need an epsilon.

sick mural
leaden ice
frozen mesa
#

so how can i fix that? do you have any idea? thanks for the help btw

leaden ice
sick mural
frozen mesa
#

so i need to attatch the shooting script that is on the pistol2 in the Hiearchy to the field Shooting Script in the inspector

leaden ice
#

Is this just supposed to be creating an ammo pickup for your gun?

#

The ammobox doesn't need a reference to the gun script to do that

frozen mesa
#

i have the bullets mechanism in the shooting script and im increasing the bullets from the ammobox script

leaden ice
#

yeah but that;s a backwards way to do it

frozen mesa
#

so i want to increase bullets when is the ammobox collected

leaden ice
#

the player should just detect that it walked over an ammo box and add the appropriate ammo to the appropriate gun

#

the ammobox itself doesn't need to reference the gun

#

if you REALLY must do it that way, you can make the assignment at runtime whenever you process walking over the box

frozen mesa
#

thanks now i have an idea how to do it by another way thank you.

hard viper
#

a quick question from yesterday, as I’m still not sure. If I have my kinematic rigidbody.MovePosition(pos2) from pos1, and pos2 touches a wall, is the timeline:
FixedUpdate:
-MovePosition to pos2
-Simulation generates contacts at pos1
-Calls OnCollision callbacks for contacts of pos1
-Update()
-Update()

-Update()
-FixedUpdate()
-Physics Similation starts at pos2, makes contacts for pos2
-Collision callbacks for touching walls at pos2

Is this correct? or no?

leaden ice
hard viper
#

no

leaden ice
#

There will be no OnCollision callbacks then

hard viper
#

all gone. but full kinematic contact

#

which seems to give OnCollision callbacks anyway

leaden ice
#

Does it now? interesting

#

but yeah your timeline looks correct to me

hard viper
#

yeah, i think full kinematic contacts was added so you can use kinematic rigidbodies with a custom physics system, or custom character controller, and still get callbacks

#

i’m trying to figure out grounding check timing, since I have my own new pseudo physics engine, so I have more ability to screw around and customize

#

I probably want to do all my grounding checks at the start of fixedUpdate, but some of the knowledge isn’t quite well-timed

#

like, right now I check OnCollision checks to see if I am touchings wall/floor, jumpable ground, spikes, slippery floor… And I think all of that is just happenning at the wrong time because it uses last frame’s info

dense void
#

!code

tawny elkBOT
hard viper
#

I’m trying to figure out how to do a ground check using contacts in 2D, so that all my info is up-to-date at the start of a FixedUpdate. Is there a way to get contacts like this?

My concern is GetContacts get contacts from last physics update, which is a frame late.

dense void
#

ship must rotate around planet. Ship must launch into space upon pressing space. ship must rotate clockwise if top half, counter clockwise if bottom half. Ship is kind of doing that but also not, it is getting confused and flipping variables and stopping after hitting 360 degrees.
https://paste.ofcode.org/33byF6CSTiE3NdTcBnssWNA
https://paste.ofcode.org/BS7AM4d28MbGddhVCpGCcb
probably easy fix but braincells are minimal at the moment

hard viper
#

in 2D, if I use OverlapCollider and Collider2D.Distance, can I just recreate the same information contained in a Collision2D, but at any time?

static matrix
#

can I run the same async function on two separate threads?
I presume so

hard viper
#

actually, how do you figure out when you have multiple points of contact between two colliders? To get several contact points?

static matrix
#

I think you can do getcontacts?

#

idk if there can be out params for this but its a start

hard viper
hard viper
#

I need to know what it would look like right this second

static matrix
#

is that an issue?

hard viper
#

yeah, i’m running a custom physics simulation

static matrix
#

ohhhh

#

well you can do overlapboxall, and that puts everything overlapped into an array

#

if I understand your earlier questions right

hard viper
#

the weird thing in fixed update is that contacts i think are generated from your position at the start of the physics simulation for kinematic RBs?

static matrix
#

maybe?

hard viper
#

I can use OverlapCollider to find all colliders

hard viper
# hard viper

the issue is if I have that red circle with multiple points of contact, I need to know each point of contact

static matrix
#

it should put them into an array?

#

unless this isnt anything to do with the Physics2D class, even on the script end

hard viper
#

that outputs an array of colliders

#

i’m in 2D

static matrix
#

well now you have an array of colliders, and you should be able to GetContacts or something similar on each of them

hard viper
#

GetContacts gets contacts as of last physics update

#

i need contact points as of right now, after colliders have all been moved

static matrix
#

huh

hard viper
#

my rigidbodies are all kinematic right now

#

so if I set .MovePosition to pos2 in FixedUpdate, then I only get contacts generated for being at pos2 after the NEXT fixedUpdate

#

actually, maybe the GetContacts methods are different? one doesn’t specify getting contacts from last physics update.

devout solstice
#

is it possible to have a if statement go across multiple methods, i have a if statement and i need multiple methods to run under the same condition and i don’t want to have to put the same if statement in each method

somber nacelle
#

store the result of the condition in a bool field

#

or just pass the result of the condition to the other methods as a bool parameter

devout solstice
#

oh parameter, true

unreal thunder
#

Hi
I am trying to save playerprefs in android upon calling OnApplicationQuit() or OnDisable() or OnDestroy()
Currently saving via OnApplicationQuit() but did try all others too
Upon quitting application via Exit button working fine
but if player is swipping up the application playerprefs not storing
Can anyone please tell me why and how can I fix this?

heady iris
#

You may not receive an OnApplicationQuit message at all here.

#

Consider saving when the application loses focus.

unreal thunder
#

yeah I think OnApplicationPause() might work here

rigid island
#

but yeah prob want pause

On Android, when the on-screen keyboard is enabled, it causes an OnApplicationFocus( false ) event. If you press Home when the keyboard is enabled, the OnApplicationPause() event is called instead of the OnApplicationFocus() event.

unreal thunder
buoyant violet
#

I want to create some helper function in unity. i will put them in a script (ex: helper.cs). i will use these functions in many other scripts. how should I implement that helper script? First thing come to my mind is put all functions in helper.cs in a class and create a reference to that class whenever I want to use them. Is this the right way?

somber nacelle
#

make them static methods

heady iris
#

Precisely. You make something static when it doesn't need to be called on a specific instance of its class

#

Mathf is just a pile of static methods, for example

#

You can also use the static keyword on the class itself to make sure that every method on it is static

simple egret
#

Mathf itself is not static and that angers me

somber nacelle
#

it's also a struct

heady iris
#

I was about to say that it's a static struct. Wrong!

#

I remembered the struct trivia, but not that it's not static...

hard estuary
heady iris
#

You may also be interested in extension methods.

#

They let you add new instance methods to an existing type.

#
public static class MyCoolExtensions {
  public static Vector3 Halve(this Vector3 vec) {
    return vec / 2;
  }
}
#

for example

#

new Vector3(1,2,3).Halve() returns [0.5, 1, 1.5]

timber lichen
somber nacelle
#

What would be the best way to determine if an object can "see" a light? like not specifically the light source, but the light given off from light sources?
I know i could probably do something like a distance check from nearby light sources to see if their light would be visible from that range, but that doesn't really account for possibly seeing the light shine on a nearby object or whatever.
This is for a horror game where ideally I'd like enemies to react to seeing light. I've already got a shader that can do stuff if light shines directly on them, but that shader doesn't really apply to this problem.
If there's not really a performant way to do this, i'll just fake it with the distance check, but if someone happens to know how one could achieve this behavior that would be great

buoyant violet
#

oh thank you guys

#

btw, i often get lag on VS while using Unity. don't know if this is a software problem or my CPU is not strong enough. I am not even working on a complicated project, I just create a Tilemap and 2 scripts but it get lagged every time I made change to the scripts. I'm using a Dell Laptop.

leaden ice
somber nacelle
#

should only be a couple at any given time, i'll see if i can make that work

knotty sun
buoyant violet
# knotty sun Do you see the line that says Page File? Do you know what that means?

In computer operating systems, memory paging (or swapping on some Unix-like systems) is a memory management scheme by which a computer stores and retrieves data from secondary storage for use in main memory. In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. Paging is an important part of...

heady iris
knotty sun
hard viper
heady iris
#

I did also implement that. Enemies shoot rays forwards and see if there's a clear path to a light source (e.g. a flashlight with a spotlight on it) from where the rays hit

rigid island
#

tried this a while back with render texture and read pixels but gave up half way. Was trying to do Shadow/Hidden feature like Splinter Cell

heady iris
#

so, very primitive ray-tracing...

hard viper
#

it’s raytracing with one iteration

heady iris
hard viper
#

at least that is what box wants i think

heady iris
#

I tested this pretty thoroughly at one point, but it's been a hot minute and I didn't write anything down..

rigid island
heady iris
#

That's where the realtime GI comes in

#

It affects light probes

#

Although it won't be completely accurate, since you're measuring how much light is bouncing off of surfaces and affecting the probes

#

You probably want something more...reliable, anyways

hard viper
#

idk how unity implements light, but if they have any collider-like functionality, this would be trivial. You give an invisible light to the observer, and see where it intersects an actual lit zone

heady iris
#

It can be hard to tell what is "light" and what is "dark" when you just use the light probe values directly

rigid island
#

what would that be ? (something more reliable)
might need to revitalize this project if I can get this probe thing going.

hard viper
#

the way box describes it, it looks like he is considering this as either binary (light yes/no) or something with a simple threshold (light > value)

heady iris
#

you would just do physics queries for the relevant lights

#

I have not found a way to sample probe volumes yet, so I can't switch to those 😦

hard viper
#

yeah, i would tackle this from a physics perspective and not a lights perspective. unless the Lights module specifically has like a perfect method for this

somber nacelle
#

that just gets the lightsource rather than the light itself. for example a player hiding behind something shines a flashlight across the room to a wall that the enemy can see, i'd ideally like the enemy to "see" that light shining on the wall.

heady iris
#

yeah, raycasts are how I've accomplished exactly that

#

and it worked very well

#

I believe I raycasted from the flashlight to the wall

#

then raycasted from the wall to the enemy

#

and then calculated a score based on how well that second ray lines up with the enemy's forward vector

heady iris
somber nacelle
#

ah yeah, that sounds like it would work pretty well

mild orbit
#

If I have a list of GameObjects in the scene, the only way at runtime to check if they are a instance of a prefab, is to have a component on each one with a field referencing the original prefab. And check that instead of the instance, right...?

heady iris
#

The field would wind up referencing the object itself

#

Why do you need to know if they're an instance of a prefab? What are you trying to do?

sweet raft
#

Is there a 3D alternative for Physics2D.Distance?

mild orbit
heady iris
steady moat
heady iris
#

but that might just be the case!

mild orbit
steady moat
heady iris
#

I'm not following.

steady moat
#

I've done VFX spawing/managing and never I had to do something even close to that.

mild orbit
#

I just need to be able to check if a GameObject is a instance of a prefab 😭

Basically the FX artist setups a condition "Play sound x when the player is within 5 meters of prefab Y".

steady moat
#

It makes no sense.

#

Just instantiate the thing.

#

Whenever you need it.

mild orbit
#

Because I need a way to specify what the play at? Like if they want to play Birds_01.mp4 at the location of any PineTree_01 prefabs that are in the scene

steady moat
#

The system I loved the most was using a ScriptablObject wrapper around the VFX that specified the meta data.

steady moat
#

An alternative, is to create component such as VFX Spawner.

#

They hold all the require meta data and manage the lifetime of the VFX.

mild orbit
steady moat
mild orbit
#

I see, that doesn't solve my issue at all though...

steady moat
spring creek
steady moat
mild orbit
spring creek
steady moat
#

Why would be the where an instance of a prefab.

steady moat
#

Or, make a system to register points in your scene

#

Maybe something like a AudioSpawnPoint which contains a enum that you can filter on

mild orbit
# steady moat Just make a component in your tree prefab "VFX Spawner"

A VFXSpawner per doesn't work for this for a number of reasons, not the least of which is it has poor performance at scale.

I could register components with a manager component, but that doesn't solve the issue of needing to know if a specific component is from a prefab, just moves the problem point.

And a enum could work, but isn't really reasonable to ask the FX artist to edit some code every time they have a new scenario they want to spawn things in.

#

It isn't the end of the world if I have to have a field on the component of each instance with a reference to the prefab (set at edit time, on the prefab). Just was hoping there was a more elegant solution.

steady moat
# mild orbit A VFXSpawner per doesn't work for this for a number of reasons, not the least of...

VFX Spawner are highly scalable depending on how you code them. If they are not, it is because you made them not performant. Component without Update function are basically free. (They do not need one necessary) And if they do, they can be culled from millions possible way; You would have maybe 10 components actives at the same time.

Trying to know if component is from a specific prefab at runtime seem to me like a fundamental error. It seem obvious to me that a situation where want to change the prefab, have a prefab alternative or use no prefab could arrive. In fact, I have seen it numerous time.

Also, you should note that LD and LA are more than able to set an enum variable on a simple component or add one. And, if they are not, and they are using a prefab, it is hyper simple for you to do that.

mild orbit
# steady moat VFX Spawner are highly scalable depending on how you code them. If they are not,...

If they don't have a update loop, then do you have some sort of manager then? How does it access them and activate them? How does pooling work? Etc. That is beside the point, this is just part of a larger system that provides a API for data about the world to multiple systems. FX, AI, Gameplay, etc.

We have ScriptableObjects that contain conditions for when to spawn FX, and what FX to spawn. So, we only ever want to be using prefabs.

Whether a artist can and whether they should are two different things.

dense void
#

hey I have random planet generation and just wondering but I plan to use roughly 200ish different planet sprites for generation, my question is, is there a better way than making 200+ prefabs for it to go through randomly in an array when generating? just wondering

mild orbit
dense void
#

yeah I mean I might have them all same size or different size, I have base generation done that's fine, but just wondering if there's a way to swap sprites when generating next planet to not impact performance at all

#

or not as much as making a crap ton of prefabs I mean

sweet raft
#

I figured it out using some custom code...but I wanted to be sure there wasn't a built-in method for it first.

spring creek
steady moat
# mild orbit If they don't have a update loop, then do you have some sort of manager then? Ho...

If you have no update loop you can use a manager as you said, or events.

Pooling is a non issue and is trivial to do here.

It seem to me that you already have the spawning parts figure out, which is the only specific part for the VFX. The target part can definitely be agnostic of any system. A simple component with a ScriptableObject/Enum can do the work here. Heck, it could even contain no data and just serve as a mark.

It is true that whatever you can do and what you should is different. However, it is obvious that you should not, ever, use the fact that something is part of a prefab as a way to mark an object. Your example is prime example of that. Your object is named PineTree_01 which means that there is a 02, 03, etc. If an artist add a new prefab, then it wont be register in the system and they would not be able to even know that there is one. An other example would be if an artist want to note a specific points in the prefab, not the root of the prefab, then they wont be able to do it. I would say that it is also possible that an artist would want to add a VFX on only specific instances of a prefab and not on others. This is without talking about the fact they might want to add a VFX on an object that is not a prefab.

steady moat
sweet raft
spring creek
hexed pecan
#

Closest thing to 3D version of Physics2D.Distance that I can think of is a combo of Collider.ClosestPoint + Vector3.Distance

#

Physics.ComputePenetration might be useful too

sweet raft
hard viper
#

idk much about 3D tho, so I could be wrong

#

the difference is idk what computepenetration does with colliders that are separated

naive swallow
#

I'm completely fucking baffled. Anyone care to tell me how these two strings aren't equal? I literally copy-pasted this string into two different variables and they are apparently not equal. Did strings suddenly become reference types in C# when I wasn't looking

#

If I put in some random string like "dog" it comes up as equal

#

but when it's a file path it suddenly decides "I've never seen two more different strings in my entire life"

hexed pecan
#

Hmm could the double slash mess it up somehow?

somber nacelle
#

i can't reproduce the issue in dotnetfiddle 🤷‍♂️

naive swallow
#

But they both have them

somber nacelle
#

did you manually type the strings or did you copy/paste them?

naive swallow
#

I literally typed out the exact thing character by character to make sure it matched the one above it

somber nacelle
#

hmmm aren't string literals interned? so they should even be the same reference

#

try printing the length of the strings and make sure there isn't somehow some 0 width character in there

naive swallow
#

I fucking copy pasted you

#

There's a fucking ghost in my string

#

what are you

eager yacht
#

Looks like when you copy from there it adds an escape character to the end

naive swallow
#

Okay, I have exorcised the invisible nothing character from my text and they are properly matching.

#

Now, back to the original problem this was meant to debug, why the fuck is this in my file system and how do I kill it

#

but that's a problem for tomorrow digi

#

and why the hell didn't Trim() catch this

lean sail
#

Could it be a character that couldnt be displayed? If you print the unicode im curious what it is

somber nacelle
#

https://learn.microsoft.com/en-us/dotnet/api/system.string.trim?view=netstandard-2.1

Starting with the .NET Framework 4, the method trims all Unicode white-space characters (that is, characters that produce a true return value when they are passed to the IsWhiteSpace(Char) method). Because of this change, the Trim() method in the .NET Framework 3.5 SP1 and earlier versions removes two characters, ZERO WIDTH SPACE (U+200B) and ZERO WIDTH NO-BREAK SPACE (U+FEFF), that the Trim() method in the .NET Framework 4and later versions does not remove.

cosmic rain
#

Some OS localizations are pain in the ass

#

The other day I had to debug an UE4 issue where 2 spaces were not the same in the french locale. Apparently the organization responsible for deciding on characters decided somewhere in 2017 they want several different characters for spaces in french language specifically.

#

And since we were using an older UE version it wasn't prepared for that.

naive swallow
#

File system's haunted got it

heady iris
#

i can completely believe it

sharp skiff
#

So I have a circlecast2D and I got it working as I want but I want to add one more function. I want to make it so that the render line gradually grow from the origin point to the end point. Not instantly rendering. Im not sure if I should be trying t mess with the circlecast2D or the render line. Ive tried both ways but with no luck. Ive looked online and did not find anything helpful but maybe I dont know what to look for. If anyone has any good ideas or resource I can check out that would be awesome, thank you.

steady moat
sharp skiff
#

Thanks @steady moat I'll check that out.

swift falcon
#

Am I misunderstanding "OnValidate"? I thought it's meant to be called whenever something in the inspector changes?

Right now it only calls if I use "Ctrl + Z" to undo a change, any manual changes to things like collider size doesn't appear to call it?

cosmic rain
#

So changing another component shouldn't call it.

swift falcon
#

Oh.. I thought it was tied to changes on the object itself but that makes sense then

#

What would be the best way to track if collider sizes change while in the editor then?

#

actually 2 secs

cosmic rain
#

2 seconds passed

swift falcon
#

I have my own Update function in an editor script which I can just use there then

#

Yeh registered to "EditorApplication.update" I'll just do it in there

#

Initially I wanted to only check when there are actual changes, but I guess I'll just have to periodically check instead

pale wraith
#

any able to give me a hand? i'm an artist that knows very little about code but trying to create a power jump

#

i got the jump working but i can't figure out how to reset the value of the power jump after he lands

limpid onyx
#

Hey, im trying to get realtime data from a server/network and i dont know which way is best. I know something about REST api's or websockets. does anyone know which one is best to use? or more options? :)

void basalt
#

TCP sockets should be enough for just barebones connectivity. Really depends on what you're doing on the grand scale.

pure scarab
void basalt
pure scarab
#

i think you can click here

void basalt
#

try running the profiler when you start the game

#

idk if the profiler will lock up either, but it should give you a good idea as to what's happening

pure scarab
#

i bet it will lock up but i'll see

cosmic rain
pure scarab
#

i linked the pasteofcode link there now as well

cosmic rain