#💻┃code-beginner

1 messages · Page 241 of 1

polar acorn
#
  1. This shouldn't be in Update
  2. DDOL doesn't make copies. You're loading a scene that has this object in it, so it's going to load it
wintry quarry
#

The copy is made when you load the scene

golden ermine
#

So I should make this data load when I press load button in menu

wintry quarry
#

just store the GameState on this script in a variable and stop

#

let those other scripts read the game state from this script when they start up

golden ermine
#

Im a beginner I just find youtube tutorial so thats why I have it like that, I find it easier to make other things to save if I have it like this but I do understand what you mean by that

wintry quarry
golden ermine
#

okay I will try that

#

so that means I wouldnt even need to have all that in loadFromJson function, only string json etc and GameState data = JsonUtility etc

wintry quarry
#

exactly

#

That's all the save system should be responsible for anyway

golden ermine
#

why is error here at data, i doesnt say why i have to restart my VS

wintry quarry
golden ermine
#

i did this

wintry quarry
#

Yeah I know

#

I'm saying you didn't make the data field on SaveServiceSystem yet

wintry quarry
golden ermine
#

yea i removed it

#

that resets my data right=

wintry quarry
#

sorry I made a typo in my example above

#

I mixed up two identifiers gameState and data

#

but still you do need to make the data field on SaveServiceSystem to store the loaded data.

golden ermine
#

this is my full code for saveservicesystem

#

its to big so that i dont need to send screenshot

wintry quarry
#

sure and like I'm saying you need to add the field

golden ermine
#

yes i dont really understand how to add that field

wintry quarry
#

Do you understand the difference between local variables and fields?

golden ermine
#

what data in instance.data represent

wintry quarry
#

it represents the game data you loaded

#

but you need to actually make the field

#

you probably want to go through some basic C# stuff

golden ermine
#

like [SerializeField] data

wintry quarry
#

it doesn't need to be serialized

#

but no

#

it also needs a type

#

fields need a type and a name

golden ermine
#

this good? @wintry quarry

queen adder
#

the forum is more like something to find and learn specific

wintry quarry
golden ermine
#

ok so now i do it for death count and player pos

#

i did it @wintry quarry for everything

#

but i put all of that in start but what if my data is null then it like if i start new game, then it will just be default settings like death count will be back to 0 or? Will it affect anything because that is in start method

wintry quarry
golden ermine
#

ok what now after i did that

stuck jay
#

I've heard two times that it's good practice to separate your visuals from your code, so you'd make two different gameobjects and make an empty one the parent then add rigidbody, collider and scripts to it. Would breaking this to put a GunTurret.cs script on a tank's barrel be a bad thing? The way I'm planning to do this is by making it so each barrel has different stats and every few levels you can choose a better barrel.

rich adder
#

You could also just make a script that manages all the barrels, or just use SO

stuck jay
#

Actually yeah, this is about time I learned how to use Scriptable Objects

#

Well, after I write the actual barrel and tank functionality

queen adder
rich adder
stuck jay
queen adder
#

oh okay

#

Sounds interesting

#

But reasonable

#

never thought of that jet

neon ivy
#

I have a trigger to check if objects are within range of a planet, but since the planet is tagged with terrain, the ground check goes off immediately upon touching the trigger. is there a way to turn this off?

short hazel
#

Prefer physics queries such as Physics.CheckSphere() to detect if objects are nearby, instead of a collider. It's probably less expensive than a collider too!

neon ivy
#

well I need to add to a list on enter and remove from a list on exit...

#

I guess I don't need to but

short hazel
#

Then use Physics.OverlapSphere() instead which returns an array of colliders you can iterate on

neon ivy
#

ok I'll try that

#

thanks :D

shell sorrel
#

if using it often would use the non alloc version

#

but yeah best tool for i just want all colliders within a area

neon ivy
#

though how will I know if an object left the range

shell sorrel
#

what do you mean by left range

neon ivy
#

do I keep track of a list and decouple any that don't appear in the list the frame after?

frigid sequoia
#

Ey can I like... do a loop over a specific folder to get references to all objects there and store them a List or do I have to do it manually one by one?

neon ivy
#

I was using ontriggerenter and exit, idk where to put the exit code now

shell sorrel
#

oh if you care more about if things enter or leave the range would just use a collider

#

if you just want everything in range at the current moment would use the OverlapSphere

neon ivy
#

collider had an issue,
but that aside which would be more expensive.
a trigger or an overlapSphere every frame

shell sorrel
#

i would worry about what is the best soultion before worrying about performance

neon ivy
#

then overlapSphere cuz it doesn't have the issue I have rn xD

short hazel
#

With a physics query you do not need a collider. The code initiates the query and receives the result

shell sorrel
#

pre allocate a array outside of your function with the max amount of items it might carry

#

that way you can use the NonAlloc version and not incure garbage per frame

short hazel
#

And pass a layer mask, so you don't get unwanted objects

neon ivy
#

I would prefer not to specify a max if possible

#

it wouldn't be an issue now but it might be later

shell sorrel
#

the NonAlloc version costs way less to call, which is why it was recommended

rich adder
#

huge differences when you profile, you'd be surpised..

neon ivy
#

hmm maybe I'll just assign a higher max for objects that need it then

shell sorrel
#

also just set a max that is like dobule what you expect

rich adder
#

iirc

shell sorrel
#

and that it is not possible with the way its passed in

#

since its not a out parm but a reference and arrays do not resize

short hazel
#

And make sure to only loop with a for loop, and up to the number OverlapSphereNonAlloc() returns. Else you'll get null values, or values from older queries

rich adder
#

its not? dam could've sworne.. im prob just remembering wrong

neon ivy
#

for loop over foreach?

shell sorrel
shell sorrel
rich adder
short hazel
#

Yes because you do not want to go through the whole array, as it may have filled less elements than the actual capacity

shell sorrel
#

because the array will be larger then the results

#

the function returns the count

rich adder
#

yea sry must've misremembered 😅

shell sorrel
#

the reason why this costs less to use, is instead of allocating memory on call you give it a array to reuse

#

but it might not fill it every time

neon ivy
#

ok I'll use overlapSphereNonAlloc UnityChanClever

shell sorrel
#

the array should be a field not a local variable as well

eternal needle
neon ivy
#

learning more every day UnityChanOkay

shell sorrel
rich adder
neon ivy
#

the overlapsphere, in update or fixed update?

rich adder
#

update

short hazel
# neon ivy <:UnityChanThink:885169594560544800>

If you re-create a brand new array each frame, just to pass it to the method, then it's basically useless. You allocate as much memory as the regular OverlapSphere.
Whereas with a private Collider[] _bodies = new Collider[50];, it will never be re-created and will always fill the same one

neon ivy
#

ah right

rich adder
#

sometimes I run it inside a Coroutine while loop with yield return 0.2ish
if I need checks without too much frequency/accuracy

shell sorrel
short hazel
#

Yeah there's a lot of ways to optimize it. One would be to reduce the query frequency if you're far from everything, and increase it if there's objects that are close

shell sorrel
#

splits the work over many frames

neon ivy
shell sorrel
#

coroutine pauses

rich adder
#

yup

shell sorrel
#

coroutines require a active object to run

neon ivy
#

ah ok

shell sorrel
#

its the same reason why need a instance of a scene object to use StartCoroutine as well

polar acorn
#

Does it pause or does it stop? I'm pretty sure it stops entirely right, you can't resume from where it was

neon ivy
#

ah so that's why you can't start a coroutine from a scriptable object

stuck jay
#

Any way to make a 'cooldown' for a method?

#

Without writing a function specifically for it

#

I don't want to write the same function 3 times

shell sorrel
#

is it a shared cooldown

#

or a cooldown for each one

rich adder
#

if i didnt misunderstand that ur asking

stuck jay
# shell sorrel or a cooldown for each one

Cooldown for each one, the scripts are entirely separate (so for example, cooldown for firing a gun and another for damage immunity so my player won't get annihilated after stepping on the funny red block)

stuck jay
shell sorrel
#

so could have a cooldown function that accepts a delegate

rich adder
shell sorrel
#

so 1 function that takes your other function as a argument

rich adder
ivory bobcat
#

Write your own timer

stuck jay
ivory bobcat
#

An even bigger mess

stuck jay
shell sorrel
#

its common to need to write your own stuff to handle a exact case

golden ermine
#

Why cant I use instance of my SaveServiceSystem code like this

shell sorrel
#

but its very easy to abstract said things and reuse them

stuck jay
shell sorrel
#

why get it again

ivory bobcat
rich adder
shell sorrel
#

like looks like you are trying to access it like a singleton when you already got the component from GetComponent anyways

polar acorn
short hazel
shell sorrel
rich adder
#

ah ye true 😅

shell sorrel
#

persnally i would just keep it simple and use a simple timer counting delta time over frames

#

and return early on the function

#

if i had a lot maybe abstract it a little

stuck jay
#

Okay awesome, just ran into another issue

golden ermine
#

I want it to load this

stuck jay
#

If I added health for a damage cooldown script I'd have to add an Update() function to actually decrease the timer

golden ermine
wintry quarry
wintry quarry
# golden ermine

you shouldn't be doing this, just use SaveServiceSystem.instance, always

#

you don't need drag and drop or anything

stuck jay
#

And uhh, considering I'm gonna have 1k or so objects in the game that have health, this isn't going to be light

#

Any solutions?

shell sorrel
#

it will be fine

#

stop worrying about it

#

if you need cooldown on 1k objects you need to track 1k timers

golden ermine
shell sorrel
#

there is no avoiding that

rich adder
#

Too early in development to be thinking about that stuff

#

just make your game work first

golden ermine
shell sorrel
#

a timer is just adding or subtracting a number

#

costs almost nothing per frame

wintry quarry
shell sorrel
#

like a ns or 2 at most

short hazel
stuck jay
#

I'm not worrying too much about performance but I'm adding precautions for the future

golden ermine
#

because i didnt understand it very well and I complicated things for me i find this easier if it will work

wintry quarry
#

it won't work, so no it's not going to be easier

stuck jay
#

Well not adding, I'm not implementing this right now

shell sorrel
#

you are just overthinking things mate

#

get the logic working and easy to read first

summer stump
polar acorn
#

just use the instance you already have

golden ermine
wintry quarry
#

I showed you what to do

#

you keep trying to do something else

golden ermine
#

because u went somewhere and idk how to do it alone so i backtracked

summer stump
summer stump
golden ermine
#

what is version control?

golden ermine
summer stump
summer stump
golden ermine
#

I already did

#

it doesnt load my data

summer stump
#

You have fixed the error, so that is step one

faint sluice
golden ermine
#

yes

#

this is that code

faint sluice
#

Is the function being called?

golden ermine
#

yes

short hazel
#

It says "0 references" here

#

Are you calling that from a button or something?

faint sluice
golden ermine
#

i have it on button

faint sluice
#

I'm still thinking the coroutine object is not a DDOL, but let's see

polar acorn
eternal falconBOT
north scroll
#

my dash isnt workingpublic void OnDash()
{
Vector2 dashing = Vector2.right * dashSpeed;
Debug.Log(dashing);
rb.AddForce(dashing);

}

I get 20, 0 in the console from the debug but when I press the dash button, it doesnt move. Ive tried rb.velocity as well, weirdly enough, it works if I do Vector2.up (like the jump), but not left or right

polar acorn
golden ermine
golden ermine
faint sluice
polar acorn
#

If this is a normal scene object it's going to get destroyed when you leave the scene and the coroutine will never finish

golden ermine
#

no

polar acorn
#

it'll be gone by then

golden ermine
#

oh i only made ddol saveservice script

golden ermine
faint sluice
#

Load scene is being called , and because of that menu manager is being deleted before it can call loadData

north scroll
# polar acorn Are you setting `rb.velocity` to a fixed value somewhere else in code

move = inputMap["Move"].ReadValue<Vector2>(); //value of movement per the binding I set

Debug.Log(move.x);

//the velocity.x of the player is equal to the value input-ed by the analog stick/A-D keys,
//velocity.x is changed depending on isCrouch status
//the velocity.y retains, will be modified only when OnJump is called

if (isCrouching)
{
rb.velocity = new Vector2(move.x * crouchSpeed, rb.velocity.y);
}

else rb.velocity = new Vector2(move.x * walkSpeed, rb.velocity.y);

yea in fixedUpdate, thats why I changed it to addforce but i still see nothing being changed. even if its one frame thats being overridden, I dont understand why the addforce wouldnt apply

polar acorn
polar acorn
eternal falconBOT
north scroll
golden ermine
#

is this good

faint sluice
north scroll
#

sry :(, i thought it was short enough

polar acorn
# golden ermine is this good

That'll work but unless CheckMenu is also a DDOL you're gonna lose the reference to it as this object transitions between scenes

golden ermine
#

I need checkmenu only in main menu, checkMenu is gameobject ui that will when I click new game show another UI with "are you sure - yes/no" buttons

#

but also it destroy on load

#

it doesnt go to another scene

#

did i write it wrong

faint sluice
polar acorn
ionic zephyr
#

why when I make my build the objcts in my canvas are disordered???

north scroll
#

im still confused it as to why it adds the upward force, same code as jump, but doesnt apply a left or right force

polar acorn
#

Why not have something in the new scene run the LoadFromJson in Start?

polar acorn
north scroll
#

oh

#

right

polar acorn
#

Every frame, your X velocity becomes move.x times whatever speed

golden ermine
polar acorn
#

it doesn't matter what it used to be, it is now that

golden ermine
polar acorn
ionic zephyr
#

Why do the objects in my canvas move whenever I make a build?

faint sluice
golden ermine
faint sluice
#

When pressing NewGame set bool to false

golden ermine
polar acorn
golden ermine
#

yes but its not in in main menu scene because that is starting point and i only save data from game scene

#

and then I cant assign player and camera script in main menu

#

cause they are only in game scene

faint sluice
# golden ermine wait what that does how is that gonna help im confused now

Keep a bool in save system , for when you want to load data and not

When you press NewGame set that bool to false, and when you want that data to be loaded after changing the scene set bool to true before changing the scene

And in the new scene inside the start load data if that bool is true, otherwise not

polar acorn
golden ermine
#

Yes I know I should have changed that but this was easier way and I understand it more I dont think I will know how to convert it to player script and cam script to tell save script what to save

shell sorrel
#

save system in my game does not care what the data its saving is, the data just needs to implement a interface and be passed in

summer stump
golden ermine
#

and make it 1920x1080

#

i guess

polar acorn
golden ermine
#

yes haha i understand

polar acorn
#

You're gonna need to really learn how references work, and how to work with singletons, and re-do a significant portion of your infrastructure if you want to be able to save and load data

#

otherwise any time you intend to add anything, it's going to necessetate changing dozens of scripts

golden ermine
#

but can I somehow make it work as things are set now

north scroll
queen adder
#

Can i get help with something? I am making a database for a leaderboard and I want make it to that when the player dies their user and score is input to the leaderboard. Everything ive tried so far isn't working?

north scroll
#

cuz I added this to FU() but its not working either:

if (isCrouching)
{
rb.velocity = new Vector2(move.x * crouchSpeed, rb.velocity.y);
}

else if (isDashing)
{
rb.AddForce(new Vector2(move.x + dashSpeed, rb.velocity.y));
}

else rb.velocity = new Vector2(move.x * walkSpeed, rb.velocity.y);

golden ermine
polar acorn
# golden ermine can I?

Rework your save system so that it exists in all scenes and does not reference any game objects.
Have the objects in the new scene get their starting data from the save system when they're created.
Then all you need to do is tell the save system whether or not to load the JSON before changing scenes and everythign will be in place

golden ermine
#

Okay I will try

golden ermine
#

like i mean do I put it in void start etc

#

cause if I put it in void start it will at the start of game scene tell to load camera data and I only want it to load data if player pressed Load Game in main menu

polar acorn
golden ermine
#

so here for example I need camera max/min pos and camera pos to reference save

polar acorn
golden ermine
#

and I need to convert all of this to player script and cam script

#

so they reference save not save reference them

polar acorn
# golden ermine this one yea

So don't do that. Instead, in start, have camController check this object, and set its own minPos and maxPos to whatever this object has in data

golden ermine
#

okay and where to tell it to save

polar acorn
#

And make the save system default to the values you want minPos and maxPos to be when you start a new game

polar acorn
golden ermine
#

I meant to load not save sorry, I save my data trough button in my game scene

#

I meant where to tell it to load camera min/max pos and its normal pos

polar acorn
#

You have the camera get its minPos and maxPos on start. They'll get whatever data the save system has for it

#

If you've loaded the JSON, it'll be the data from the JSON

#

If you haven't, it'll be whatever default value the save system has

golden ermine
#

yes but u said to remove reference for camera and player

polar acorn
#

The save system should not reference the camera or the player

golden ermine
#

yes

polar acorn
#

Those objects should get their data from this object

#

which can be referenced from anywhere

golden ermine
#

I just delete this lines

polar acorn
#

because it's a singleton

polar acorn
golden ermine
#

yes and then I do SaveServiceSystem.instance.data.camMinPos = minPos;

#

in camera script

#

for example

polar acorn
#

Is that what you want to do

golden ermine
#

well when I click Load Game in main menu I want it to load: Camera min and max pos, camera position where it was last saved, player position where it was last saved and death count

#

so yes

#

and then I would do same for maxPos and its position and then similar thing in player script right?

polar acorn
golden ermine
#

yes like this

#

SaveServiceSystem.instance.data.camMinPos = minPos;

#

right?

#

wait sorry

#

minPos = SaveServiceSystem.instance.data.camMinPos;

#

like this

#

so that would set its minPos to last saved data

polar acorn
#

The one you want to set is the one on the left of the = sign

#

that's the value that changes

#

[Thing to change] = [Value to change it to]

golden ermine
#

yes

#

minPos = SaveServiceSystem.instance.data.camMinPos;

#

like this

#

but i still dont know where to put that line of code

#

in my camera controller script

#

i cant put it in start cause I dont want it to load everytime u start game only when u start game by load game button

golden ermine
#

ohh okay

#

so in start

#

thanks

queen adder
rich adder
neon ivy
#
int count = Physics.OverlapSphereNonAlloc(transform.position, range,_colliders,mask);
Debug.Log(count);
``` my overlapSphere isn't detecting my player. the player tag is in the mask and the player is tagged :C
rich adder
neon ivy
#

I mean it has the layer mb

queen adder
#

its working now i believe

rich adder
queen adder
#

i just need to make the leaderboard

neon ivy
#

nothing, count is 0

#

it's not even detecting its own collider

rich adder
#

is mask a layermask

neon ivy
#

yes

rich adder
#

see make sure its where you think it is too

neon ivy
#

I did

rich adder
#

show it

rich adder
neon ivy
rich adder
# neon ivy

ok , n which one is the script with overlap

neon ivy
#

when my player falls in it won't detect it

rich adder
#

does ur player have a collider?

#

i dontsee it

neon ivy
#

ye it's at the bottom

#

this is the script, it's on the sphere

rocky canyon
#

whats the issue? cant find the OP

rich adder
#

overlap not detecting Player

rocky canyon
#

ahh, classic

rich adder
#

not seeing something obvious 😢

wintry quarry
rocky canyon
#

if u squint it appears to have one

#

can we see the player's inspector?

rich adder
neon ivy
#

this is the entire update

protected virtual void Update()
{
    int count = Physics.OverlapSphereNonAlloc(transform.position, range,_colliders,mask);
    Debug.Log(count);
    for(int i = 0; i < count; i++)
    {
        Debug.Log("found Collider");
        _objects[i] = _colliders[i].gameObject;
        CustomGravityObject gravityObj = _colliders[i].GetComponent<CustomGravityObject>();
        if (gravityObj != null && !influencedObjects.Contains(gravityObj) && gravityObj.enableCustomGravity && gravityObj.isGravityStateAccepted(gravityType))
        {
            AddGravityObject(gravityObj);
        }
    }
    foreach(CustomGravityObject gravityObj in influencedObjects)
    {
        if (!_objects.Contains(gravityObj.gameObject))
        {
            RemoveGravityObject(gravityObj);
        }
    }
}
wintry quarry
#

i bet that's a CharacterController which is technically a collider but I don't think they show up in raycasts/queries

neon ivy
#

nah, capsule collider and rigidbody

rocky canyon
#

ya, triggers are the only thing a CC will activate

wintry quarry
rocky canyon
#

show the player

wintry quarry
#

looks like it's on a child object

#

is the child object in the right layer?

neon ivy
wintry quarry
#

and what layer is this object in?

neon ivy
#

Player

rocky canyon
#

yea show the entire inspector plz

neon ivy
#

it's the parent

wintry quarry
#

note this appears to be a child of the above

rocky canyon
#

and the hierarchy

wintry quarry
#

Then what's teh "Capsule" object?

rocky canyon
#

sorry if we seem to not belive u..

neon ivy
#

Player doesn't have a mesh, just the collider and rb

#

capsule is just the mesh

rocky canyon
#

thank you.. and the layer is correct?

#

can we see the mask in the inspector

rich adder
#

it was when I saw it

neon ivy
wintry quarry
# neon ivy

Ok and where is this overlap query located? Is it the yellow thing? The player doesn't seem to be inside that

neon ivy
#

when I click play the player falls into it

rocky canyon
#

i meant the mask of the script

rich adder
rocky canyon
#

yea, lol looks like its off the damn map

#

hacks i tell you!

rich adder
rocky canyon
#

ok welp, idk

rich adder
#

now I want to see the capsule enter the Sphere Gizmos!

rocky canyon
#

unless ur overlapsphere is super small

neon ivy
#

the overlapsphere and gismo use the same range float

rocky canyon
rocky canyon
neon ivy
#

ye just transform.position

#

does it matter that it's being called as base.update() from a script inheriting this?

rocky canyon
#

but is this centered up on the planet graphics?

neon ivy
#

it shouldn't cuz the debug.log is being shown

rocky canyon
#

damn bro..

#

thats odd

neon ivy
neon ivy
rich adder
neon ivy
rich adder
#

make sure ur not reading any older Logs

rocky canyon
#

heres one that records from ur browser..

#

dont have to download anything.

neon ivy
#

I got obs

rocky canyon
#

^ oh well use that

#

ShareX is better 😛

#

shareX = little files

#

OBS = big ass files

rich adder
#

true, in OBS yu can just reduce the filesize too btw

neon ivy
rocky canyon
#

ya, but thats a hassle..

neon ivy
#

it's only a couple seconds

rocky canyon
#

very odd

#

@rich adder we're overlooking something

rich adder
rocky canyon
#

at this point i'd say isolate the code...
make a new gameobject.. with just that single overlap call

neon ivy
#

I'll try with normal overlapsphere

rich adder
#

doubt that will make difference

#

there is prob something very obvious we're not looking at UnityChanDown

rocky canyon
#

when i run into an issue like this where i can't explain it.. its normall the system as a whole.. something in the system interfering... and i prove that by making a simple gameobject/ simple script with just the part thats broken and see if that registers the thing

rocky canyon
#

he has a rigidbody.. its not kinematic.. its on the root GO, the mask is Player.. the layer is player.. the collider is sufficient size.. the overlapsphere originates from planets center..

rich adder
#

in the inspector

neon ivy
#

planet test has the PlanetGravityAttractor

#

oh

rocky canyon
#

oh

rich adder
#

ahh is the mask field correctly assigned there?

neon ivy
rocky canyon
#

one possibility is the transform.position is not centered to the planet u think it is

#

(that would be if the graphics were off-center of the parent) or w/e

#

but if ur drawing gizmo's from teh same point i dont think thats it either

rich adder
#

you shown PlanetGravityAttractor but log is coming from GravityAttractor

rocky canyon
#

but could u show the planet test uncollapsed, and the inspector

rich adder
#

or is that because its inherited

neon ivy
#

ye

rocky canyon
#

he metnioned that earlier

#

but i dont know about inheritance so i dropped out

neon ivy
edgy prism
#

Hello, nullable bools?

public IEnumerator SetOverheadEmoji(string input, bool? isAnimating = null)

can I use this to do

while(isAnimating)
rich adder
#

Ahh

#

a null ref

rocky canyon
rich adder
#

was that always there?

neon ivy
#

that's with the normal overlapsphere

rocky canyon
#

this doesnt have anything to do with it does it

rich adder
#

oh wait nvm u asked something else.

neon ivy
#

normal overlapsphere is getting a count of 2 and then goes into the code I guess with an entry of null

edgy prism
rich adder
rocky canyon
#

good call using that method.. atleast u know its positioned correctly

#

what two colliders does it get?

#

does it get its own collider?

pallid nymph
neon ivy
rocky canyon
pallid nymph
neon ivy
#

ye I checked, it's the capsule and the trigger

rocky canyon
#

but NonAlloc doesnt?

neon ivy
#

yep

neon ivy
#

why nonalloc so mean

rich adder
#

are you sure u allocated enough size?

neon ivy
#

it has a size of 10

rocky canyon
neon ivy
#

I set them to a new array in start

cosmic dagger
#

How big is the radius?

neon ivy
#

15

pallid nymph
# edgy prism Hmm how come?

if you have a nullable bool and it is null, .Value will throw an exception, so make sure you handle the null state properly

rocky canyon
#

his gizmo may be misleading

#

u are correct

neon ivy
rocky canyon
#

he says he uses the same variable for the gizmo..

edgy prism
# pallid nymph if you have a nullable bool and it is null, .Value will throw an exception, so m...

Ahh ok so I should be ok if im running other code when it is null?

if (isAnimating == null)
            {
                for (int i = 0; i < animatedThinking.Length; i++)
                {
                    overheadEmoji.sprite = animatedThinking[i];
                    yield return new WaitForSeconds(0.8f); // Wait for 0.8 seconds
                }
            }
            else if (isAnimating!= null)
            {
                while (isAnimating.Value == true)
                {
                    for (int i = 0; i < animatedThinking.Length; i++)
                    {
                        overheadEmoji.sprite = animatedThinking[i];
                        yield return new WaitForSeconds(0.8f); // Wait for 0.8 seconds
                    }
                }
            }
rich adder
#

just sanity check gizmos and overlap are in the same script yes?

neon ivy
#

ye

rich adder
#

baffling

cosmic dagger
#

Did they already show the LayerMask to make sure it's correct?

rocky canyon
#

take the performance hit and use regular overlap? ¯_(ツ)_/¯

neon ivy
rocky canyon
#

lol, im not seeing the issue..

neon ivy
#

most likely me doing something wrong xD

rich adder
#

Debug.Log(count, gameObject)
make sure it is running from the correct script just in case

rocky canyon
cosmic dagger
#

Bc the only difference is that nonalloc needs a collection provided. It should work correctly . . .

rich adder
#

yeah they should work the same

cosmic dagger
#

Do you have the code posted to look at? I want to check the collection used . . .

rocky canyon
#

he used regular overlap and it does register

#

super freaking odd

neon ivy
#

how do u send large code again?

#

I'll just send the entire script

rocky canyon
#

use a paste bin site

rich adder
#

!code

rocky canyon
eternal falconBOT
rocky canyon
#

show us the entire code..

cosmic dagger
rocky canyon
#

yea, maybe with the entire code block something will stand out

#

me and nav are not seeing it

neon ivy
#

in the inherited class it mostly just calls base.Update()

rocky canyon
#

^ thats the only oddball part that i can't help with

#

not sure that matters

neon ivy
#

wait...

rich adder
#

uh oh

rocky canyon
#

did u rubber duck urself?

neon ivy
#

UnityChanPanicWork \

#

override start where

rich adder
#

nice

rocky canyon
#

lol.. bro

pallid nymph
#

😄

rocky canyon
#

i want my 10 minutes back

neon ivy
rich adder
#

had a funny feeling inheritence had something to do with it

neon ivy
#

wait nvm the ohno, start wasn't virtual

rocky canyon
#

me too.. b/c nothing else made sense

cosmic dagger
#

I figured smth was amiss with the code. It all comes back to the code . . .

rich adder
#

yeah good call on that

rocky canyon
#

facts..

#

by u asking for the entire script it revealed the culprit

pallid nymph
#

yeah, I also knew something was off with something... it always is 😒

#

😝

rocky canyon
cosmic dagger
#

Once they mentioned calling base. Smth was missing a base call or access to the base method . . .

rocky canyon
#

soo.. whats the fix?

rocky canyon
#

enlighten me.. as someone not familiar with inheritance

rich adder
neon ivy
#

make start virtual -> call base.Start() in the inherited class' override start

cosmic dagger
#

They did not make Start virtual so it can be overriden and call to the base method . . .

rocky canyon
#

ahhh, cool cool TIL

rich adder
#

antother reason I usuaully stick to composition when possible 😛

rocky canyon
#

lol! j/k glad u figured it out 🙉

neon ivy
rocky canyon
#

actually... lets thank the rubber duck

neon ivy
#

rubber duck OP

rocky canyon
#

always is

neon ivy
#

but plz still buff

rocky canyon
#

i've never had an issue with comp

pallid nymph
#

right 😄

rocky canyon
#

much easier to debug imo

#

u damn near need breakpoints everywhere to debug an issue with inheritance

#

(atleast i would)

rich adder
#

yeah and sometimes you want to use abstract methods because you want child classes to do something parent only defined

#

but then you mind as well use Interfaces

crisp anvil
#

when using Instantiate to spawn a GO in the world the scripts that are attached to it, Do their constructors run?

rocky canyon
#

interfaces im cool with

neon ivy
#

interfaces I've only recently learned

rocky canyon
#

even inheritance im okay with.. as long as im not overriding stuff

rocky canyon
rich adder
rocky canyon
#

who summoned me?!

shell sorrel
#

yeah on Instantiate Awake, Start OnEnable will be called

crisp anvil
#

class x

public X {
variable assignments here
}

?

shell sorrel
cosmic dagger
shell sorrel
pallid nymph
#

but like, Awake, OnEnable immediately (in most cases) and then later Start

shell sorrel
#

use Awake Start and OnEnable

crisp anvil
#

ok, so then would void Awake work?

#

oh ok

shell sorrel
#

yup

crisp anvil
#

Each Awake / start/ update is associated with thier own specific object and not hte class in general

shell sorrel
#

jsut a side effect of how components are done you cant use the constructor directly

crisp anvil
#

thanks

#

appreciate it

cosmic dagger
#

@crisp anvil if you want to activate or setup a script on a GameObject, use its Awake, OnEnable, or Start method . . .

shell sorrel
#

we got both Awake and Start so you can make some assumptions

#

generally Awake setup your internal state

#

in Start you can assume everyone else has run Awake and setup external stuff

rich adder
#

there is also this assuming you use poco

public class SomePoco
{
    public string Something = "";
}

public class Foo : MonoBehaviour
{
    public SomePoco somePoco; // will get new() automagically
}```
#

same with Lists/Arrays

cosmic dagger
#

Awake = internal
OnEnable = switch code on
Start = external
OnDisable = switch code off . . .

crisp anvil
#

That is good to know, I tried using the new keyword and monobehavior didn't like it

rich adder
#

yup, you cannot new components since they're UnityEngine.Object

rocky canyon
#
public class SpawnerScript : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            SampleClass sampleInstance = new SampleClass(42);
            sampleInstance.Initialize();
        }
    }
}```
```cs
public class SampleClass
{
    private int storedInfo;

    public SampleClass(int info)
    {
        storedInfo = info;
    }

    public void Initialize()
    {
        Debug.Log("Initialization method called.");
    }
}```
#

i also just usually use an Initialize method. that i call right after i Instantiate..

#

if its a regular monobehavoiour

rich adder
#

Yeah I usually have Init methods because to reset games I prefer not to reset the whole scene + other reason ofc

rocky canyon
#

ya, i have setups where i need to know who spawned it..

#

but i havent figured out a better way to do it.. than to use an Init method..

#

but that may be the best way..

pallid nymph
#

yeah I think it's a reasonable way to do that

rocky canyon
#

neat, no refactor for me!

#

ive slowly starting using Non Monobehaviours for data type stuff..

#

but it sketches me out tbh

#

not sure when/how imma break something

rich adder
#

when you do anything outside of Unity you cannot help it but use pocos

pallid nymph
#

hey, best way to learn is to break things in various ways! 😛

shell sorrel
#

feel like tons of my code was always structs and regular classes

cosmic dagger
#

Init methods are great for MonoBehaviours. My problem is naming some Init and others Initialize. OCD issues . . .

rocky canyon
pallid nymph
rocky canyon
#

i take no chances

pallid nymph
#

haha, git should be pretty much enough 🙂

#

(given that it is both local and non-local)

rocky canyon
#

yea but ive had conflict errors that fuckd up my entire project

#

thankfully i had local zips

cosmic dagger
#

I use Git but keep a backup on an external hdd. You never know . . .

rocky canyon
#

like once.. i had a git that i tried to push.. and it would get to 99 percent and just fail

shell sorrel
#

its always possible to fix a issue on git with conflicts

rocky canyon
#

then it was screwd from then on

#

i couldnt fix it to save my life

rich adder
rocky canyon
#

i have somethign in common with the mighty Random!

rocky canyon
#

perhaps u have the magic touch to help me out

cosmic dagger
#

I hardly commit or forget to. I guess I haven't lost enough to commit fully, though I do recommend it to everyone . . .

rocky canyon
#

its not really a conflict as more of a failure to push/pull

shell sorrel
#

at work we got a few vcs systems in use, but code is pretty much just git, then a monthly backup of the server the remote is on runs

#

we do use perforce for the artists though instead of git. draw a very hard line vs source art and gameready art

rocky canyon
#

i learned github during a gamejam.. it was a terrible experience 😄

cosmic dagger
#

That's what I hated the most; losing art from failed drives. That shit made me quit. I do miss making 3D art . . .

stuck jay
#

This is a very stupid question but I can't test this in-game now, can you attach multiple identical scripts (as in, the same script) on the same game object?

cosmic dagger
#

Yep . . .

#

But they're harder to distinguish from if attempting to access an individual instance with code . . .

stuck jay
cosmic dagger
rich adder
#

otherwise no guarantee which one GetComponent grabs

#

i think the one added first but never tested that, just assuming lol

cosmic dagger
stuck jay
#

Don't think I'm ever gonna need to call that script, just going to be an ammo pickup and I don't want to make an entirely new script for picking up an object with multiple ammo (like the backpack from doom)

rich adder
cosmic dagger
#

But multiple runs could yield different results . . .

cosmic dagger
rich adder
#

why not just make an array instead of multiple scripts

rocky canyon
#

you could ^ yea

stuck jay
rocky canyon
#

would be much better

rich adder
#

at least thats what I got used to making my Data be SO

stuck jay
#

Though an Array would probably not work since it's constant

#

So list

rich adder
cosmic dagger
#

A backpack with different types of ammo sounds like an array of SOs for each type of ammo . . .

rich adder
#

yeah thats exactly how I do mine ^

stuck jay
rich adder
stuck jay
#

I don't see the point in copy pasting the ammo pickup code just for one item

rich adder
#

you dont need backpack seperate script is what Im saying

stuck jay
#

Why do all of that instead of making a list though?

cosmic dagger
stuck jay
#

Oh

#

Damn, I forgot

rich adder
#

yur ammo pickup script can be both . And your player can tell if its backpack if contents of list ammo types is > 1

stuck jay
#

You can change the array size before runtime

#

In the inspector

rich adder
#

yes since they're placed at scene

stuck jay
#

This is what leaving unity for 6 months does to a mf

tender stag
#

when im walking up a slope on the side im not walking forward but also to the side, why? cs moveDirection = orientation.forward * y + orientation.right * x; slopeMoveDirection = Vector3.ProjectOnPlane(moveDirection, slopeHit.normal);

slopeVelocity = Vector3.ProjectOnPlane(rb.velocity, slopeHit.normal);

if(slopeVelocity.magnitude > moveSpeed)
{
    float a = slopeVelocity.magnitude - moveSpeed;
    Vector3 o = -slopeVelocity.normalized * a;

    rb.velocity = rb.velocity + o;
}```
```cs
rb.AddForce(slopeMoveDirection.normalized * acceleration);```
rich adder
#

if you had dynamic things like chest then yes something not-fix would make sense, like dictionary or list

rocky canyon
tender stag
#

lmao

#

i need to put other important stuff on there

rich adder
tender stag
stuck jay
rich adder
#

I still do just use inspector for private vars though by using Debug mode

rocky canyon
rich adder
#

I dont have to create like 1000 diff things and link them inside inspector, each script has their own debug

rocky canyon
#

i think it just depends..

#

if ur in code.. and just wanna see the variables OnGUI is fine.

#

but if u wanna show it off or juice it up.. UI all the way

rich adder
#

oh yeah def just for debugging. Never for the Player 😛

naive pawn
tender stag
#

i need the friction to be set to 1 which is the max

#

but thats only for walking

#

and i also need the friction to be 0 to block the player sticking to walls

#

what do i do

cosmic dagger
rocky canyon
rich adder
rocky canyon
#

yup, never made it into a game or anything.. just for debugging.. but it felt sly

rocky canyon
rich adder
tender stag
#

but i cant do that

#

for the walls

#

im thinking of adding a second collider

#

for only half the player

#

from the middle going up

rocky canyon
#

like a wall collider?

tender stag
#

yeah

#

making it like 0.01 bigger than the normal one

#

so u wont really notice it

#

with 0 friction

#

but i'd also have to scale it properly with the actual one

lost anvil
rich adder
lost anvil
#

what do you mean?

rich adder
wintry quarry
rocky canyon
wintry quarry
#

GIven that you're doing a local move on the x to -1.5, I would guess you haven't standardized anything

lost anvil
#

no?

tender stag
#

i cant have him rubbing on the wall

#

with 1 friction

#

and if its 0 then the movement against the wall will be sloppy

rocky canyon
#

ahh true.. i didnt think of that

tender stag
#

i'll try adding a second collider

rich adder
# lost anvil no?

can you select one of the drawers in scene mode and show the Pivot point with move tool

summer stump
rocky canyon
#

perhaps?

lost anvil
#

i dont know what standardizing is

summer stump
rich adder
rich adder
# lost anvil

yeah select it on Local mode and not in center mode or Global

lost anvil
#

same thing just moved down

rocky canyon
#

should have containers fitting around the drawers so ur axis' are all the same..

rich adder
rocky canyon
#

the front of the drawer should always be facing the (certain) axis

lost anvil
rocky canyon
#

if its not.. slap it inside a empty container.. rotate it to make it right.. and move that container instead

rich adder
#

so -x is correctly going inwards, you need + X

rocky canyon
#

+x would go outward ^

#

for that drawer

lost anvil
rocky canyon
#

thats the hard way

rich adder
#

perhaps store on each object what their open direction will be

rocky canyon
#

or that ^

#

could use a vector3.. +1, 0, 0

#

would be the opening direction..

#

-1,0,0 for the other way

rich adder
#

unless you wanna go through each thing that opens and fix it with pivot parent or blender

lost anvil
#

no thanks

rocky canyon
#

if its just one so far.. that wouldnt be so bad

lost anvil
#

blender is cancer

rocky canyon
#

nah bro.. ur insane

#

ur psycho

#

lock em up

rich adder
#

fixing pivot is easy in blender but sure lol

lost anvil
#

bro i can only make block and export block

#

theres too much stuff

rocky canyon
#

everything starts with block 😄 lol

lost anvil
#

and all the beginner tutorials just make donuts lol

#

true

rich adder
#

personally all my drawers are so the Z is always forward this way there is no second guessing but yes its time consuming

rocky canyon
summer stump
rocky canyon
#

r to rotate.. shift + a to apply rotation

#

and ur done

tender stag
#

now i gotta do the scaling

#

i hope having two colliders wont be a problem in the future

#

lmao

rich adder
rocky canyon
polar acorn
lost anvil
#

okay

rocky canyon
#

ya, theres not much it doesn't show u..

#

if he animated a chunk being bit out of it.. it'd be the ultimate blender tutorial

rich adder
#

gamedev is problem solving, you need to figure out this one has many fixes

polar acorn
#

There's a reason basically every 3D animator knows about The Donut.

rich adder
#

you could just make an empty parent on each drawer with correc Z

rocky canyon
#

if it were me id use Nav's suggestion and have a orientation vector and just change that in the inspector depending on ur drawers

#

or throw them inside an empty container.. and make that face the right way instead

#

two solid solutions

rocky canyon
#

thats the 2nd best one ive ever seen

tender stag
#

could someone help me always center and scale this collider accordingly to the one above?

rocky canyon
#

copy values and paste?

tender stag
#

when i crouch and uncrouch

#

and crawl

#

the height and center changes

prime cobalt
#

Does anyone have any idea why my rigidbody would be moving way slower backwards than it does forwards but not have that issue when going left/right with this? They should be identical...

rich adder
prime cobalt
#

ok

prime cobalt
#

ok

meager steeple
#

is there a way to see the version history in visual studio code?

wintry quarry
rocky canyon
# tender stag

ya, u have to change the center variable on ur collider when u do such things

prime cobalt
rich adder
prime cobalt
wintry quarry
#

!code

eternal falconBOT
prime cobalt
wintry quarry
#

Not seeing anything in this code that would cause it. It would be from something else probably

#

anywy Update should not be used for physics

crisp anvil
#

in a list when you remove at entry
Listname.removeat(5) for instance

the list collapses on the deleted entry.
I save that index point at the GO's creation so the saved Index's for each GO after 5 will be wrong 6 will be 5 and so on. What a good way to update all the ID's?

any better way than

in a method
for ( int 1 = 0, i < Listname.count; i++ )
{
listname[i].id = i;
}
?

wintry quarry
#

don't use the list index as an id

prime cobalt
rich adder
#

FixedUpdate()

wintry quarry
#

and if you need to look these things up in the list from some ID, you should be using a different data structure, like a Dictionary

wintry quarry
crisp anvil
#

I apologize, let me rephrase, I don't use it as a ID however I use a int called IndexReference that stores the GO's index.

wintry quarry
#

don't do that

#

store a different kind of ID

crisp anvil
#

oh ok

prime cobalt
#

ok I'll move it there and look through the other scripts Shiva_ThumbsUp

rich adder
rich adder
# prime cobalt

are you sure maybe you didn't animate the transforms by accident or something maybe overriding it

tender stag
#

in HandleHeight i need to set the height and center of wallCapsuleCollider accordingly```cs
public CapsuleCollider capsuleCollider;
public CapsuleCollider wallCapsuleCollider;

private float defaultHeight;
private Vector3 defaultCenter;

private float defaultWallColliderHeight;
private Vector3 defaultWallColliderCenter;

private void Start()
{
//Height
defaultHeight = capsuleCollider.height;
defaultCenter = capsuleCollider.center;

defaultWallColliderHeight = wallCapsuleCollider.height;
defaultWallColliderCenter = wallCapsuleCollider.center;

}

private void HandleHeight()
{
float targetHeight;
Vector3 targetCenter;

if(isCrouching)
{
    targetHeight = crouchHeight;
    targetCenter = crouchCenter;
}
else if(isCrawling)
{
    targetHeight = crawlHeight;
    targetCenter = crawlCenter;
}
else
{
    targetHeight = defaultHeight;
    targetCenter = defaultCenter;
}

capsuleCollider.height = Mathf.Lerp(capsuleCollider.height, targetHeight, heightDuration * Time.deltaTime);
capsuleCollider.center = Vector3.Lerp(capsuleCollider.center, targetCenter, heightDuration * Time.deltaTime);

wallCapsuleCollider.height = ;
wallCapsuleCollider.center = ;

playerModel.localScale = new Vector3(playerModel.localScale.x, capsuleCollider.height / 2, playerModel.localScale.z);
playerModel.position = capsuleCollider.bounds.center;

}

#

the wallCapsuleCollider has an offset

#

bottom is wallCapsuleCollider and top is capsuleCollider

prime cobalt
rich adder
#

since you said it moved slower?

crisp anvil
#
    public static bool RemoveNPCByID(int id)
    {
        NPC npcToRemove = npcInGameList.Find(npc => npc.npcID == id); // find npc id in list

        if (npcToRemove != null) // if found remove
        {
            npcInGameList.Remove(npcToRemove);
            return true;
        }    
        return false; // didn't find for some reason
    }

With this i can do it without storing a index. Better solution ?

prime cobalt
#

Oh I think I found the issue it was in the script I used for turning the gameobject

lusty flax
#

I don't know why, but this snippet of code for a moving platform I made just does not work. The issue is that the character doesn't stick to the platform; it always slides off and doesn't stick to the platform like I want it to. What's supposed to happen is that the character gains the velocity of the platform in order for it to move along with it at the same rate. However, this isn't working. I even disabled the friction portion of my character controller while the character is on a moving platform, but that hasn't fixed anything. All collideable objects in my game have a Friction: 0 PhysicMaterial attached to them (on their colliders & rigidbodies).

time += Time.deltaTime;
Vector2 movementVector = targetPosition - initialPosition;
movementVector.Normalize();
rb.velocity = movementVector * time * velocityMultiplier;
Debug.Log(playerRB.velocity);
if (checkForCharacter())
{
    playerRB.gameObject.GetComponent<CharacterController>().negateFriction = true;
    playerRB.velocity += (rb.velocity - previousVelocity);
}
else
{
    playerRB.gameObject.GetComponent<CharacterController>().negateFriction = false;
}
previousVelocity = rb.velocity;

Context:

  • This is a 2D game.
  • This is all running in FixedUpdate.
  • checkForCharacter() checks if the character is standing on the platform (this function works 100%).
  • previousVelocity is just a variable to keep track of the platform's velocity in the last FixedUpdate.
  • The platform moves to the target location as intended.
modest dust
wintry quarry
lusty flax
shut crag
#

I’ve been reading about it for three days, but I haven’t had the chance to sit down and code yet… am I correct in understanding animator velocity is available without using a RigidBody?

austere hedge
#

I want to disable a script after it finishes running. If I know the name of the object that has the script, I can turn it off.

GameObject.Find("Cube").GetComponent<ScriptNameHere>().enabled = false;

But I don't want to hard code "Cube" because this script could be attached to other objects as well. What do I replace "Cube" with to select the object that the script it associated with?

shut crag
#

i’m animating an object under a rigid body so I can’t add another one, but I’m trying to get its velocity and Google is saying animators have a velocity and angular velocity

wintry quarry
shut crag
wintry quarry
#
public ScriptNameHere example;```
trail heart
#

A gameobject can only be controlled by an animator or by a rigidbody at any given time

shut crag
#

If someone animates a sword to move in a direction, and then you moved it that way with a rigid body instead, would you still get generally the same information?

wintry quarry
#

It's probably talking about when using an animation with Root Motion

shut crag
#

Yeah it says to enable that 😛

wintry quarry
austere hedge
wintry quarry
#

All you need now is example.enabled = false;

austere hedge
#

I took it from a snippit on stackoverflow

wintry quarry
#

You need to think about what the code is doing

#

you are blindly copying things without understanding

#

that's not a good way to learn

#

A better way to learn is to go here: !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

austere hedge
#

Thanks for your help.

trail heart
# shut crag Yeah it says to enable that 😛

What says to enable what?
Root motion is a vector represention motion baked into a root transform of an animation clip
It can be applied into a rigidbody, a charactercontroller or a transform
All three work in different ways so depending which one you use Animator.velocity may also return different values
But it really depends what your setup is like
If your animator is correctly giving the rigidbody forces via root motion maybe it'll return the value you expect

wintry quarry
shut crag
trail heart
shut crag
#

I have a rigid body and an object that is a child it that is animated by players that use one platform out of a game that supports multiple different platforms, so I’m trying to get the animated object’s velocity when animating but use the parent RB for the other people

#

If ticking to apply root motion passes the values to the rb anyway then I guess I can just leave it on

#

My issue was that the items weren’t having very good gravity physics when apply route motion was enabled, and the objects aren’t held, so I’ll probably just toggle that on grab

#

And pray that that works 🙏

lusty flax
wintry quarry
lusty flax
#

why does it say java...?

wintry quarry
lusty flax
#

oh... yeah i forgot about that...

#

thanks

tender stag
#

could someone help me out with this?

#

i need to set the height and center of the wallCapsuleCollider accordingly to the capsuleCollider

#

and the wallCapsuleCollider has a different height and center

wintry quarry
#

it's really not clear what the relationship you want to have between them is though

tender stag
#

top is capsuleCollider
bottom is wallCapsuleCollider

wintry quarry
#

sounds like you probably want a remap function

tender stag
#

what is that?

wintry quarry
#

e.g. remap(capsuleCollider.height, minCapsuleHeight, maxCapsuleHeight, minWallHeight, maxWallHeight)

tender stag
#

im not sure that i need that

wintry quarry
#

pretty sure you do

frigid sequoia
#

Isn't this supposed to return an int?

tender stag
#

i've already got all the values

wintry quarry
tender stag
wintry quarry
#

there's a separate RountToInt

wintry quarry
grizzled zealot
#

I'm facing a strange problem:

In Start() I set enabled = false. But it seems that Update() gets still executed once before Start() finishes its execution and disables the script.

How come Update() gets called even once if I have enabled = false in Start()?

wintry quarry
#

So yeah it's still gonna happen

#

Can you use Awake instead?

grizzled zealot
#

What do you mean? I need something that runs before Update(). Does Awake() run before?

#

I don't want to start messing with constructors, because I think MonoBehaviour doesn't want that.

slender nymph
#

Awake runs earlier than Start

pearl lodge
#

Is there a way to change the color or alpha of a 'Tile'?
public Tile tile;

strange dune
#

Can anyone explain to me why this doesn't work? I'm attempting to make text flash on and off till E is pressed.
Help would be greatly appreciated (;´д`)ゞ

modest dust
#

yield return can be only used within an IEnumerator

#

etc

strange dune
#

Ohh okay

#

Would it work without the yield return maybe..?

modest dust
#

nope

#

unless you play around with a timer and some if statements

#

but that's messy

#

just learn how to make a coroutine

pearl lodge
modest dust
#

Yeah, that but with a few additional stuff if you don't want a massive bunch of coroutines playing at the same time

#

Update is not needed

#

Can be placed within Awake/Start and looped

shell sorrel
#

well more some problems are better suited to coroutines and some update

reef patio
strange dune
wise oyster
#

How can I make a script that can change the mesh from a sphere to a capsule or vice-versa? so far I have been able to identify the mesh filter component but not much else

wintry quarry
#
myMeshFilter.sharedMesh = whatever;```
pearl lodge
strange dune
wise oyster
wintry quarry
swift crag
#

Mesh is a kind of unity object.

wintry quarry
#
public Mesh HappyMesh;
public Mesh SadMesh;``` for example
swift crag
#

It's just like referencing a material, or a prefab, or whatever

wintry quarry
#

Yep, it's an asset like anything else

wise oyster
#

ohh i think i know what you mean, cheers

nocturne violet
#
UI_transform.pivot = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

hey does anybody know how to change the pivot by the mouse position? I tried doing it but it just flies off the screen.

wintry quarry
nocturne violet
wintry quarry
#

i.e. 0.5, 0.5 is the center of the object, no matter where it is

#

you need to convert the screen space position of the mouse into normalized coordinates within the object

pearl lodge
thin hollow
#

do overrided methods always do whats inthe base method too?

wintry quarry
#

they replace the base method

strange dune
thin hollow
wintry quarry