#archived-code-general

1 messages · Page 323 of 1

lean sail
#

You'll need to show code, also this heavily depends on how you're actually moving the player. Like through physics or something else

feral forge
#

Okay, I'm using a playerController that's based around Quake movement

#

I'm opening my visual studio right now but here's a snippet of how I'm creating the death floor in a sense

lean sail
feral forge
pastel patio
#

Actually, It's generated based on a csproj file, the one called... I forgot, it contained a list of all my scripts for compilation

I've put it into Scripts/MessagePack/Resolvers

feral forge
pastel patio
#

Guys does anyone have an idea how a file might become completely isolated from the rest of the project? I don't have access to any of my scripts in global nor custom namespace in that file

#

The context I'm in is the GeneratedResolver.cs made by mpc, it's currently in Assets/Scripts/MessagePack/Resolvers and appears to not have access to any of my structs

pastel patio
#

Uh, I'm not quite sure what you mean with that...

#

If you're talking about public/protected/private etc... no, I'm just simply blocked from any of my own scripts, I can still access UnityEngine, UnityEditor, System etc, but no, none of my own.

#

Blocked as in, my intellisense don't find their existence, and Unity also log errors saying that they don't exist

#

I've tried giving some a custom namespace too, it worked as much as keeping them global- not.

chilly surge
#

Do the errors only show up in the generated resolvers, or any script in that folder? Try creating your own script in that folder and try to access something in the project and see if that raises an error.

pastel patio
chilly surge
#

What's not found?

pastel patio
#

Strangely they never specified where I'm meant to put the resolver tho...

#

So I put it in the package's folder

chilly surge
#

It doesn't matter where you put it as long as it's discovered by Unity.

pastel patio
chilly surge
#

Are those your own structs?

pastel patio
#

The generated script includes it, but it throws errors cus can't be found, while I'm using those all throughout my project

pastel patio
chilly surge
#

Can you show the generated code?

pastel patio
#

Sec...

#

Have fun 😊

#

Jk Idk if you can make any sense of this, either way the error marks all occurrences of global::SavedObject and global::StructureData as can't be found

#

And I tried using, where it became clear that all my own stuff are inaccessible

knotty sun
pastel patio
#

It is indeed the file generated by mpc and the one where the errors occurs

knotty sun
#

there are no references to global::SavedObject and global::StructureData in it and the vast majority of it is just commented out

pastel patio
#

Ah, I forgot that I commented the vast majority out when I wanted to wipe some errors to confirm some stuff

#

And I do clearly see occurrences of global:SavedObject and global:StructureData in there

#

Line 53, 72

chilly surge
#

Are your SavedObject and StructureData in the global namespace, or are they in your own namespace?

pastel patio
#

115

pastel patio
#

I'm sure that global or my own namespace, none are visible in intellisense

chilly surge
#

Yeah that's probably the issue, global::SavedObject looks for it in the global namespace, so if you moved them to your own namespace like MyGame.SavedObject then that won't be found.

pastel patio
#

No, the issue existed before already...

#

And like I insisted all this time, I know that I simply can't access them no matter the namespace...

#

I've been trying to solve it for hours on end earlier today

chilly surge
#

What namespace is your SavedObject now?

pastel patio
chilly surge
#

Can you try putting _ = typeof(ALS.Base.SavedObject); in one of the method's code and see if that raises an error?

pastel patio
#

I heard about something called Assembly definition... Thought that they do compile certain things independently from all the rest, so I've been wondering if I wound myself up in the package's assembly definition

pastel patio
#

Even using ALS.Base; is invalid, I've got access to everything except from those

#

Whelp, pointless for today since I can't test anymore, cya tomorrow guys

#

Gotcha! I was allowed to test despite it being late and stuff... I'm dying to know what I wasted my day on, guess what?

Both of my thoughts were true! There is an assembly definition asset in the folder, and moving it out of the folder does clear the errors... That was a real dumb waste of time for me

wintry crescent
#

why can I not do this (error can't implicitly convert UISystemBase to T), while when dropping the "where" part, it works?

#

alternatively, since an "explicit conversion exists" apparently, how do I do that?

#

oh wait, I figured it out, had to do return (T)result; instead of return result;

knotty sun
wintry crescent
knotty sun
#

all good

sturdy kindle
#

I have a method within my ParticleManager called ShowParticles() but it's not showing up here within my OnAttack invoke. What's the scope needed for this to show up?

flat hill
#

it must be a public method

sturdy kindle
#

I added an overloaded method and it worked. Something with the number of arguments I think.

wintry crescent
#

I have something like this:

public void RegisterForUIEvent<T>(Action<UISystemBase, bool> toRegister) where T : UISystemBase
{
    if (_uiSystems.TryGetValue(typeof(T), out var result))
    {
        result.OnOpenClose += toRegister;
    }
}

and in UISystemBase I have:

public event Action<UISystemBase, bool> OnOpenClose;

But I can't figure out how to instead be able to put

public event Action<T, bool> OnOpenClose where T : UISystemBase;

I hope it's clear enough what I'm going for here?

#

oh, maybe this'll help make it clearer:

public void Start()
    {
        UISystemManager.Instance.RegisterForUIEvent<UIInventorySystem>(OnInventoryOpened);
    }

public void OnInventoryOpened(UISystemBase uiSystem, bool wasOpened)
{
            
}

I'm trying to be able to recieve <UIInventorySystem> in OnInventoryOpened, instead of UISystemBase

quartz folio
#

If toRegister was also generic it would work fine, presuming result is casted to the same generic set up

wintry crescent
#

type or namespace T wasn't found

quartz folio
#

The whole class needs to be generic to use generic fields or properties

wintry crescent
#

the class is a base class for said T

#

so I was hoping I could do something like that

latent latch
#

why* is your method of type T and non of your params are T

wintry crescent
#

my point is to pass an object of type T, instead of an object that is the base of T

#

but I guess this is too complicated I'll just cast it in the final method

quartz folio
# wintry crescent the class is a base class for said T

I don't know what that means. If you need to use a generic argument in a field then you need to make the class itself generic, and then its members can use that argument (and it doesn't need to be redefined in the methods too)

latent latch
#

I think you probably want some type of generic wrapper

wintry crescent
#

making a generic out of it would be way too much hassle because I just wanted to spare myself some typing in the methods at the end of the event chain, so that's pointless

quartz folio
#

... Why? That sounds like a job that polymorphism/inheritance already handles

wintry crescent
#

...I might be overcomplicating the thing I'm working on

#

but I don't think just inheritance would work in my case

#

doesn't matter anyway

latent latch
#

usually my train of thought -> I need inheritance -> I need generics -> I should just compare

quartz folio
#

I usually start programming some generic thing, hit a level of complexity I find stupid and then back off to re-evaluate my life

chilly surge
#

Sound like you want this?

- public void RegisterForUIEvent<T>(Action<UISystemBase, bool> toRegister) where T : UISystemBase
+ public void RegisterForUIEvent<T>(Action<T, bool> toRegister) where T : UISystemBase
chilly surge
#

Ah.

shell scarab
#

Is there something like the step function but for more than just 0 or 1? Like something that would round to 0, 0.5, and 1? (or whatever I set the inputs to?) Or is that something I would have to do myself?

somber nacelle
iron karma
#

anyone good with ai behaviour trees?
i want to know how are sequence nodes supposed to work

weary swift
#

Yo ! In my game I have different type of weapons and attacks. Depending on what I'm doing and using, different animations will play. In all of this animations I have to do things, activate/deactivate hitbox, allow/prevent player from doing certain things, etc... My first choice to do that was to do it using Animation Event. The problem is that it's really painful to do it that way, I have to put so many events on so many animations, and I have to create specific functions that only serve a purpose for on thing that will be used by the event, and it just take so many time for no reason. Is there any other thing that can help me get the same result but with a more modular and scalable system ? I hope the question is clear, thanks !

crisp minnow
#

I'm stumped, what's the play here? Upgraded my project from 2023 beta to unity 6. Which should I pick, and how? Picking either didn't really persist it and nothing changed.

latent latch
weary swift
latent latch
#

In that case, sounds like what you're using is probably the prefered tool for this honestly

weary swift
#

R.I.P

latent latch
#

probably some variation on how to group the animations/triggers and reuse them, but you probably do want to use the animator

weary swift
#

I will look into this a bit more then, thanks for the direction !

opaque forge
#

Guys I don't really know where to ask but are these good performances for my project? From seeing this it runs approx 200 FPS , is this considered good?

crisp minnow
#

@opaque forge Depending on how much of your game you have done, it's looking pretty good. The EditorLoop will not actually be a part of the game on release, so you'll be looking at a much higher framerate.

#

I'm stumped, what's the play here?

wintry crescent
#

Why can I not click buttons in child canvases? I have one main canvas in which everything works, but in canvases that are childobjects to main canvas, it doesn't

heady iris
#

For example...

#
  • Canvas
    • Button (Blocked)
    • Text
#

the Text might cover a very large area

#

(much larger than the actual text you can see)

wintry crescent
#

the second canvas is the issue

heady iris
#

ah, I see

wintry crescent
#

and I'm careful to deselect raycast target when it's not neccessary

heady iris
#

you could check by watching the inspector for the Event System object

#

to make sure the graphic raycast isn't hitting something weird

indigo verge
#

Is GetHashCode a good way to convert Strings into IDs for items, if I want items to have unique IDs based on their name?

lean sail
dim latch
#

Is there a package/util that let's me conditionally render variables in the editor? i'm trying to make a complex script with a lot of moving parts and having every value rendered constantly (even if not needed) is annoying

leaden ice
#

Or write your own

#

Also only serialized variables are shown in the inspector

#

Most of the time if you don't want it showing in the editor you just shouldn't be serializing it

latent latch
#

Most conditional stuff I showIf is pretty much what the particle system does

#

the choice of fields to use depending if you want constant or random range values is something I use a bunch

#

unity editor support never ever

dim latch
# leaden ice NaughtyAttributes

ok so i just downloaded naughtyAttributes and it seems pretty cool, but i can't get it to work.
This is my setup

// stage type enum
public enum StageType
{
    moveObject,
    waitForTime,
    setLerpRate
}

// animation stage class
[System.Serializable]
public class AnimationStage
{
    public StageType stageType;
    [ShowIf("stageType", StageType.moveObject)]
    public TransformData moveData;
    [ShowIf("stageType", StageType.waitForTime)]
    public float waitTime;
    [ShowIf("stageType", StageType.setLerpRate)]
    public float lerpRate;

}

//main monobehaviour
public class ObjectAnimator : MonoBehaviour
{
    public List<AnimationStage> positionalData;
}

No matter what, every option is rendered. Is it to do with how i'm making the AnimationStage class Serializable? i'm not sure how to get it to render as a list in the unity editor otherwise

#

also i just tested it, it works if i define 2 variables in the main monobehaviour

somber nacelle
#

you probably need the allownesting attribute on those too

leaden ice
#

Oh nvm

#

I'm blind

dim latch
#

Lmao

dim latch
#

Thankies :3

indigo verge
# lean sail Sounds fragile, just make an ID once and always use it. If you suddenly want to ...

I've added some robust bits to it, in response to your critique. Now, there's a dedicated "String ID", so I can easily read it, but that ID is converted into a hash, and if no String ID is provided, it uses the name of the item instead, and registers a Debug.Log error. So now the name of the item can be different from the ID String of the item, and I don't need to worry about accidentally using the same ID number for multiple items, because it will correctly log errors if that occurs.

#

Also, this only occurrs in Editor/On Enable, so it doesn't have much overhead.

green granite
#

Hey I'm having some troubles Combining animations through Layers. Is there anyone who could help me?

#

Right now I'm trying to create the classic blend between Run and Shooting animatios, but for some reason I'm not noticing yet, the character animations star doing strange things like this

cosmic rain
#

Also, this is not the appropriate channel

feral forge
#

Hi, I was wondering where do I go for help, as I'm trying to create a death floor, which works but it appears im clipping through objects on spawn

-Attempted elevating the characters/player
-Considered setting the movement speed to 0 but not sure how to call to another file/class
-changed the distance to reach the death floor

Using Scripts to create the deathfloor/checkpoint based system

When I respawn it's as if the colliders to the objects in my project suddenly turn off so I phase through them constantly falling to the death floor

feral forge
#

the top two pictures show how I respawn

#

In update

#

that's how I teleport back to spawn

#

it uses a checkpoint system too

gray mural
#

When I respawn it's as if the colliders to the objects in my project suddenly turn off

  • Do they actually turn off?
feral forge
#

That's a good question, I don't believe so I'd have to double check that

#

i think its my playercontroller as my speed increases therefore I clip through objects or something like that

gray mural
#

Do you have any errors?

feral forge
#

no, I don't which is confusing me more

hasty canopy
gray mural
#

Alright, could you answer the question about the colliders turning off? Check out in the Inspector whether they actually are

feral forge
#

@hasty canopy I was thinking that, so I elevated the initial spawn point of my character to test if it is the pivot point and I don't believe so

feral forge
#

I'll get a video of it too so you can see more in depth what's going on

gray mural
#

Right, consider also showing the colliders that are clipping

torpid depot
#

guys can someone help about thıs

#

ı deleted thıs sprite's ın scrıpt but stıll stayıng there

#

how can ı just turn on or off thıs thıng

hasty canopy
#

Did you save the script?

torpid depot
#

ı want when ı change somethıng ın code or unıty That changes fast How can ı

somber nacelle
#

do you mean you've deleted the variables? if that is the case you need to make sure to save and that you have no compile errors

torpid depot
somber nacelle
#

if only there were more than one part to that message

hasty canopy
torpid depot
#

last day ı was quıt from unıty and when ı go unıty back today that was not the same

#

there ıs no error

#

just yellow thıngs

somber nacelle
#

show the console in unity

gray mural
#

Then the script is not saved, if the variables differ

torpid depot
#

you mean thıs?

torpid depot
#

even ı am usıng rıder program That auto saves

gray mural
#

Now the variables are different from the image we've previously seen

hasty canopy
torpid depot
#

yes but why so long lıke that

#

ı need to fıx ıt If ı can

hasty canopy
torpid depot
#

maybe we can fıx that

#

ıf anyone know any tactic or way about that

gray mural
#

It doesn't recompile on its own if you don't save it properly

torpid depot
#

ı am always savıng

#

ı dıd ctrl S ın codes and ın unıty

#

but stıll that took much tıme for change varıables

gray mural
#

Your Unity is not saved though

torpid depot
#

ıs there any way for fıx thıs ?

gray mural
#

Yes, save it

torpid depot
hasty canopy
torpid depot
#

maybe ın settıngs ı need to turn on somethıng or

gray mural
hasty canopy
torpid depot
#

xd

noble pine
#

Hello everyone, I have a problem regarding throw parabolas
I want to display slanted throws etc. in Unity, but my problem is that the results are wrong compared to the real world. (They are off by about 0.4m)

            var xAngleRad = 30 * Mathf.Deg2Rad;
            var initialDirection = new Vector3(Mathf.Cos(xAngleRad), Mathf.Sin(xAngleRad), 0);
            var rotatedDirection = Quaternion.Euler(0, -90, 0) * initialDirection;
            var _projectile = Instantiate(sphere, launchpoint.position, launchpoint.rotation);
            _projectile.GetComponent<Rigidbody>().velocity =
                rotatedDirection * 15f;

Example:
S = (vo^2 * sin(2alpha)) / g
That means: A ball with V0 of 15m/s and launch angle of 30 degrees, should fly 19.86 meters.

But with my setup in Unity, the ball flies approximately 19.2 metres.
Drag and angular drag is set to 0 on the ball.
Is it simply not possible to be more precise, or should that actually work as a rule?

flat hill
#

Is your rigid body mass and gravity the same as real life?

knotty sun
#

what about friction?

flat hill
#

Maybe try to create a physics material with all exterior forces set to 0 and test what happens, like friction what Steve said

noble pine
feral forge
#

@gray mural I'm pulling up OBS for the video rn

gray mural
#

Simply ping me when the video is sent

noble pine
feral forge
brave furnace
#

Quick question, is there a way to serialize the fields within a record?

feral forge
#

@brave furnace i most likely am wrong but i think its [SerializeField]

gray mural
gray mural
#

SerializeField serializes the field in the Unity Inspector, and Serializable makes the class serializable there

gray mural
#

Note that the constructor should be derived from this, otherwise an error will be thrown

brave furnace
gray mural
#

Haven't understood the question

#

I have read it wrong enough.

brave furnace
#

but it would work 😄

hasty canopy
gray mural
gray mural
pseudo vortex
#

Is there anything wrong with this, it won't destroy the fixed joint after it collides with a wall?

brave furnace
#

When do you call CancelFire()?

gray mural
hasty canopy
gray mural
#

Also, not only you send the code as an image, you also have a light mode

feral forge
#

1 is for debuging

feral forge
pseudo vortex
hasty canopy
gray mural
pseudo vortex
#

I was following a tutorial for this, and I thought I had it all correct so idk

hasty canopy
gray mural
pseudo vortex
gray mural
tawny elkBOT
cunning raptor
#

anyone understanding 3d can look unity talk page

#

pls

hasty canopy
#

!code

tawny elkBOT
gray mural
#

Using a site

pseudo vortex
knotty sun
gray mural
hasty canopy
hasty canopy
feral forge
#

OHHH I think i found something as to why

gray mural
feral forge
#

so on the empty object (player) it never resets for location

gray mural
hasty canopy
gray mural
#

Where is CancelFire called though?

hasty canopy
#

No clue

gray mural
#

That's what I've been asking for

hasty canopy
#

Same lol

gray mural
#

It's not called correctly, and the op doesn't want to send it

feral forge
#

I FIXED IT

hasty canopy
feral forge
#

so it was the empty object, its location never respawned causing me to constantly fall

#

thanks guys for helping me fix this

gray mural
#

Have you even removed the colliders though?

feral forge
#

really was a big help, I'm doing this for an assignment

hasty canopy
#

That's why gotta be careful with hierarchy, and do fix the points I mentioned earlier

feral forge
feral forge
pseudo vortex
hasty canopy
#

That way you will know for sure

pseudo vortex
hasty canopy
pseudo vortex
hasty canopy
#

So joints are being destroyed?

pseudo vortex
#

No they keep on stacking

knotty sun
#

and does your Debug tell you which joint you are trying to Destroy?

pseudo vortex
hasty canopy
pseudo vortex
#

There's only one with a bullet script and one with a gun script

hasty canopy
#

Also since you said joints keep stacking do show the entire bullet script

knotty sun
pseudo vortex
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    FixedJoint fixedjoint;

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Wall")
        {
            fixedjoint = gameObject.AddComponent<FixedJoint>();
            fixedjoint.connectedBody = collision.gameObject.GetComponent<Rigidbody>();
        }
    }

    public void DestroyJoint()
    {
        Destroy(fixedjoint);
    }

}
#

that's the bullet script

knotty sun
#

So where is the Debug.Log to make sure DestroyJoint is being called?

pseudo vortex
#

should I have kept it on?

knotty sun
#

do NOT do that

#

yes, of course, you keep all Debug.Logs until you have solved the problem

hasty canopy
#

You shouldn't remove debugs unless problem has been solved, and even then having them stay there is plenty helpful in future

knotty sun
#

put the debug.log back and add fixedjoint as the second parameter

pseudo vortex
hasty canopy
pseudo vortex
#

like this?

knotty sun
pseudo vortex
hasty canopy
# pseudo vortex like this?

It works but next time make debugs look bit more meaningful like
Debug.Log("DestroyJoint called here"); or something like that

hasty canopy
pseudo vortex
hasty canopy
#

Never used fixed joints so I'm not sure if that's how it works. Add debug in collision enter too?

pseudo vortex
#

it looks like it is indefinitely creating fixed joints

hasty canopy
pseudo vortex
hasty canopy
#

Since there wasn't a fixed joint initially

`if(fixedJoint==null)
//fixedJoint = add joint

fixedJoint.WhateverYouWannaDo`

pseudo vortex
#
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Wall")
        {
            if (fixedJoint == null)
            {
                fixedjoint = gameObject.AddComponent<FixedJoint>();
                fixedjoint.connectedBody = collision.gameObject.GetComponent<Rigidbody>();
            }
        }
    }

    public void DestroyJoint()
    {
        Debug.Log("DestroyJoint called here");
        Destroy(fixedjoint);
    }

}
#

like this then?

#

nevermind gets an error

hasty canopy
pseudo vortex
#

tried this, and it's coming back with an error of not being able to use == on null

hasty canopy
pseudo vortex
pastel patio
#

I'd like to create save folders for my game, are there any objections to saving each of my worlds in multiple files?

#

Currently the hirarchy is like this:

  • Save1 (Folder representing save slot)
    • Game (File with binary)
    • Pebblefall Island (Folder representing dimension)
      • SaveableObject (File with binary)
      • Terrain (File with binary)
wintry crescent
#

Is there a way in which I can get all the sprites that are contained within a Texture2D, in an array, during runtime?

#

I guess I can just drag them all at once into an array in the editor. Not much more work than dragging the texture2D itself

cosmic rain
cosmic rain
paper flame
#

Is it recommended to use States for a simple AI*

#

I just did everything in a single method now haha

cosmic rain
#

There're no "recommendations". It depends on your project and preferences.

#

If it works for you, just keep it like that.

#

Unless you have concerns about it?

paper flame
#

Alright thanks

#

Well, i need to implement multiplayer soon

#

For the first time ever

versed spade
paper flame
#

And I all heard it will suck

versed spade
#

Only change was removing a time.timeScale line I didn't want

paper flame
#

possible infinite loop

cosmic rain
paper flame
#

Try something like ```cs
Debug.Log("Before SaveGlyphVertexInfo");
TMP_Text.SaveGlyphVertexInfo(...);
Debug.Log("After SaveGlyphVertexInfo");

paper flame
#

Good I have steamworks 🤣

#

but it still sucks

somber nacelle
versed spade
#

oh

#

should I try using a different textbox in there?

cosmic rain
#

I'd double check the last stack entry from your code.

somber nacelle
#

use the SetTextWithoutNotify method instead of SetText or .text =

cosmic rain
versed spade
somber nacelle
#

yes

cosmic rain
#

Before that, I'd look through the logic

simple sable
#

is using Linq here (or in general) more expensive in terms of performance than using a classic loop?

leaden ice
#

You don't need to sort a list to find the smallest element

#

But also yes there are GC concerns here

knotty sun
simple sable
#

Will avoid using Linq then, thank you guys.

heady iris
#

Linq is going to be more expensive for two big reasons:

  • Everything is a virtual method call, since everything goes through the IEnumerable interface
  • Many things create garbage
#

I still use it frequently, especially in colder parts of the code (i.e. parts that don't run often)

chilly surge
#

There are cases where Linq is more performant because it evaluates lazily, unless your handwritten replacement is also written with lazy evaluation.

#

But yeah as a general rule of thumb, avoid Linq in hot paths.

heady iris
#

indeed

knotty sun
chilly surge
#

That's still a tradeoff

#

Linq allocations are fixed cost (unless you are allocating per enumerated item), whereas lazy evaluation can save varying amount, to the point it outweighs the cost of allocation.

vale bridge
#

Is there a way to get reference to another component on the same object while running a script in edit mode?

#

So [ExecuteInEditMode] script but can also get values from other components on the same game object

#

I'm trying to run a script to keep the selector of a grid the same size in x, y values as the actual grid

vale bridge
#

or is that another issue that isn't related

leaden ice
#

NREs are always the same

vale bridge
#

Ok I think I've narrowed it down, I can successfully grab the component reference however when I try to access the value it throws me a null

vale bridge
#

where grid is of type Grid

vale bridge
leaden ice
#

How did you assign the variable?

vale bridge
vale bridge
#

I wonder if it's because Start doesn't run when it's runned in editor mode

leaden ice
leaden ice
#

the other possibility is you have another copy of this script floating around without a Grid

vale bridge
#

I'll put it in Awake

vale bridge
vale bridge
#

Maybe Awake nor Start get executed in [ExecuteInEditMode]

#

UnityChanThumbsUp Thanks!

gray mural
#

Use OnEnable for the edit mode instead

spring flame
#

linq has MinBy for that for example

#

As for the performance, just like others said, linq does cost a bit more, but it's in general negligable and you should absolutely benchmark first and foremost, bother later.

#

"Avoid using linq" is not the correct lesson that should be learned here

#

code expressed with linq is often far more readable and maintainable, and this is what you should take into account as one of the priorities as well.
It's also important to recognize, that linq can sometimes handle edge cases you can forget yourself, e.g. when a list is empty MinBy would throw InvalidOperationException while your code depending on implementation could be undefined.

crisp comet
#

Hey guys! can ParrelSync work on Unity 6?

rigid island
#

works perfect

#

better than unity built one tbh

chilly surge
#

Allocations is a much bigger concern than the isolated difference in performance.

spring flame
#

Idk if he read that as he didn't reply after "Will avoid using Linq then, thank you guys", but yeah.
Although I'm still in favor of "first, test/benchmark", then "readibility and simplicity" and only after that "optimize according to rules"

fallow quartz
#

is there any way to use apply root motion for 2d sprite renderers? I have an animation that makes 2 dashes but i dont know how to make the player to stay where the animation ends

chilly surge
#

Yes, performance optimizations should always come after profiling, and that's why it's a general rule of thumb

#

But realistically, in a hot path, allocations will be a killer.

spring flame
#

ah, and also it all depends on a use case, in hot paths yeah, avoid allocations

#

but also only after they are becoming a problem

#

I think?

#

just, be reasonable

chilly surge
#

Technically yes, especially with incremental GC, if you allocate slower than GC can clean up, you shouldn't get GC pauses.

#

But like if you have positively identified something as a hot path (eg a long live GO's Update method), there's really no need for profiling or wait until it becomes a problem, just avoid Linq right there.

simple sable
simple egret
spring flame
chilly surge
#

Do note that .NET version and C# version are different.

simple egret
#

.NET 9 will be C# 12 13

heady iris
#

i'm mildly baffled by all the different kinds of .NET versions

chilly surge
simple egret
#

Well, now there's only one being actively developed which is just ".NET"

heady iris
#

I never really know which of these is "newer"

#

i guess that's a separate concept though

#

maybe

simple egret
#

Thery're two distinct "branches" which can't really be compared

chilly surge
#
  • .NET Framework: is a runtime, Windows only. It's now considered legacy.
  • .NET: is a runtime, cross platform, the modern go to nowadays. It used to be .NET Core but Microsoft later dropped the "Core" part of the naming so it's just .NET now.
  • .NET Standard: is not a runtime. Think of it more like a contract/interface, assemblies compiled against this interface can work on any runtime that implements the interface.
crisp comet
heady iris
rigid island
#

.unitypackage that is

crisp comet
#

Oh yh...

#

Thanks 😁

torpid depot
#

guys how can ı close partıcleEffect

#

ıt follows my mouse posıtıon but Never stopıng

#

is there any settıng for ıt

leaden ice
#

and how are you playing it?

torpid depot
#

after when ı press of to mouse0 key

torpid depot
leaden ice
#

you would write code to stop it then

torpid depot
#

ohhhh

leaden ice
torpid depot
#

no

leaden ice
#

Says play on awake in the screenshot

torpid depot
#

ı put ın input.getkey

#

when ı press mouse that always playıng

#

ı dont know to play partıcle effect

#

but need to add thıs for my exam

wintry crescent
#

this is the first time when I actually do not understand a supposedly simple error message

#

There is no argument given that corresponds to the required parameter 'id' of 'InventorySlot.InventorySlot(int, bool)'CS7036

#

I have a class inventory slot (not deriving from anything) with this constructor

{
    slotID = id;
    IsOutfitSlot = isOutfitSlot;
}```
#

and when I try to derive from InventorySlot, I get that error message, on the class if the deriving class is empty, and on the constructor if the class has a constructor

#
    public class ExclusiveInventorySlot : InventorySlot
    {
        public ExclusiveInventorySlot(int id, bool isOutfitSlot = false)
        {
            slotID = id;
            IsOutfitSlot = isOutfitSlot;
        }
    }
#

this gives said error

simple egret
#

Yep that's normal

leaden ice
simple egret
#

You need to call the base constructor

wintry crescent
#

oooooooooooooooooooooh right, okay

#

yea that makes sense

leaden ice
simple egret
#

public ExclusiveInventorySlot(int id, bool isOutfitSlot = false) : base(id, isOutfitSlot)

#

And that's it

wintry crescent
#

thank you

#

works!

simple egret
#

Since that when you create your own constructor it gets rid of the default, parameter-less one, any derived class will now need to call it so the instance is properly created

gusty aurora
#

Anyone tried Unity 6 ? Is it slower than the previous versions (the same way every version is slower than the previous one) ?

leaden ice
#

That is not a trend I have noticed, but why not try it yourself?

heady iris
simple egret
#

That's because you have beefy computers
Or got used to it
I used Unity on and off over a few years, and I noticed significant slowdowns over a few major versions. From taking 30 seconds to enter play mode to having that little "Hold on" progress window pop up when you right-click something, it's getting worse as versions move forward

heady iris
#

perhaps your projects are just getting larger

#

the time taken for things like recompiles is always proportional to how much work unity is doing

simple egret
#

Nothing more than ~20 scripts as that's a major turn off

heady iris
#

can you actually measure a difference in an identical project across multiple versions of unity?

simple egret
#

No, but I vividly remember that everything was "fast" in the 2017 version compared to the 2021 one I tried a few months ago

#

When they deployed that new dark UI is the point it got worse

leaden ice
#

I mostly remember when they deployed the busy bar that people all started complaining it got slower vs when they didn't have a busy bar, and it was shown to have been purely psychological

chilly surge
#

Recompilation/domain reload performance has gotten noticeably worse since one of the versions, it significantly slows down iteration speed.

leaden ice
#

that being said I'm sure there have been slowdowns and speedups over time due to various factors

heady iris
#

"since one of the versions" is pretty vague

#

if you have a project I can recompile in two different unity editor versions and get significantly different compilation times, i would be very interested in knowing about that

chilly surge
#

Yeah I can't pinpoint exactly which one, but my first Unity project was with Unity 2019, and comparing to Unity 2022, changing a script in an empty project was significantly faster back then.

simple egret
#

Yeah and I don't know if there's memory leaks or something, but the longer you work on the project, the longer the time it takes to reload assemblies or reload domain (whatever that is) when entering play mode

heady iris
#

I have the "enter play mode" settings set to not reload the domain or scene, so i may be responsible for some of that leaky behavior

simple egret
#

Fresh editor instance is 5-10 seconds, and after 4-5 hours, it goes up to around 40, that's the time you restart it and it's back to the normal

#

And the "busy" window might be psychological for some stuff, but I've seen way too many lengthy "Application.Repaint" when opening windows or changing inspectors, pretty sure that wasn't the case before

heady iris
fleet gorge
#

2022.3.19f1

simple egret
#

The busy window probably slows down the whole thing lmfao

#

"Yeah the process is slow, but let's make it slower by instantiating a new window and pushing events to it to tell the user we're doing something"

fleet gorge
#

should I really use unity 6

paper flame
fleet gorge
#

nobody's gonna read your whole code 😴

paper flame
#

its not that big

fleet gorge
#

you didn't even tell us your multiplayer solution

#

photon? sockets?

paper flame
#

Fair, Nakama

#

Its a socket system

simple egret
leaden ice
paper flame
#

But couldnt see why

leaden ice
#

If not, start debugging your code that is supposed to spawn them

fleet gorge
paper flame
#

Wait, I think its due the matchmaking

fleet gorge
paper flame
#

I dont think there is

fleet gorge
#

how are you learning this system?

#

YouTube tutorial or by docs?

paper flame
#

docs

#
#

I think I found the issue tho

#

my matchmake doesnt make the player instance

#
using System.Collections.Generic;
using System.Threading.Tasks;
using Nakama;
using UnityEngine;

public class Matchmaking : MonoBehaviour
{
    private ISocket _socket;

    private async void Start()
    {
        await NakamaManager.Instance.Connect();
        _socket = NakamaManager.Instance.GetSocket();
        _socket.ReceivedMatchmakerMatched += OnReceivedMatchmakerMatched;
        await JoinMatchmaker();
    }

    private async Task JoinMatchmaker()
    {
        var query = "*";
        var minCount = 2;
        var maxCount = 2;
        var stringProperties = new Dictionary<string, string>();
        var numericProperties = new Dictionary<string, double>();

        await _socket.AddMatchmakerAsync(query, minCount, maxCount, stringProperties, numericProperties);
    }

    private async void OnReceivedMatchmakerMatched(IMatchmakerMatched matched)
    {
        Debug.Log("Match found!");

        var match = await _socket.JoinMatchAsync(matched);
        Debug.Log("Joined match with ID: " + match.Id);
        Movement movementScript = FindObjectOfType<Movement>();
        if (movementScript != null)
        {
            movementScript.matchId = match.Id;
        }
    }
}```
simple egret
fleet gorge
#

💥

paper flame
#

damn I need to improve my pc

#

building takes 10 minutes each time

fleet gorge
#

why you building so often

#

vr?

paper flame
#

No, anticheat

fleet gorge
#

yikes

paper flame
#

yep...

unborn dirge
#

i cant find cinemachine in my package manager

leaden ice
paper flame
#

The good thing IL2CPP wont compile everything again if you change 1 script only

unborn dirge
#

im searching it up

fleet gorge
#

if it's anticheat I can't help you but there's a thing called Multiplay which lets you run multiple unity instances

leaden ice
fleet gorge
#

so you can test multiplayer easier

leaden ice
#

there are different sections to the package manager

unborn dirge
leaden ice
#

Cinemachine will be in the Unity Registry

unborn dirge
#

oh

#

i see

leaden ice
unborn dirge
#

oh

#

i found it

#

thanks

paper flame
#

btw nakama is a very good solution for a very cheap multiplayer game

#

you only need a vps

hasty canopy
fleet gorge
#

you can diy

#

make your own sbmm algorithm

paper flame
fleet gorge
#

trying to figure out how unity websocket work because I'd rather make my own backend solution

paper flame
#

It does have those

hasty canopy
#

I m quite confused on how to go about doing it. Currently using photon for multiplayer

fleet gorge
#

photon is pretty restrictive

#

it's perfect for games like lethal company where there's no matchmaking as you always group with friends

#

and PUN can easily be integrated

#

but for anything that requires SBMM you'd probably need better authority than PUN

#

make your own server 🥱

hasty canopy
#

Yeah, currently thinking of using some service like playfab or UGS to set up matchmaking

fleet gorge
#

you can use photon quantum but idk how that goes

fleet gorge
#

Playfab fell off after being bought by ms

#

They retired the old docs so now all the links on the forum are dead

hasty canopy
fleet gorge
#

New docs are ass

#

Idk what ugs is

hasty canopy
#

Unity gaming service

fleet gorge
#

But it would be fun to make everything yourself 😈

fleet gorge
hasty canopy
#

Yea

fleet gorge
#

Though I've been told off a lot for using flask

hasty canopy
fleet gorge
hasty canopy
#

It's a 1v1 puzzle game like matchmasters

fleet gorge
#

ig photon is ok for this but matchmaking will need Playfab

ripe wave
#

How to make PlayerWalkSound disable when GameOverScreen shows or player IsDead?

fleet gorge
#

also players can cheat

#

what's a playerwalksound

#

how are you playing your sound

ripe wave
ripe wave
fleet gorge
#

we do not know what your code looks like so we can't help you

hasty canopy
#

Not looking forward to it either💀

fleet gorge
#

and chaos ensued

#

it was so dumb

#

people were spawning gigantic enemies everywhere

hasty canopy
#

Lmaooo

fleet gorge
#

I was there to witness launch

#

You should go see the videos on it

hasty canopy
#

I'll have to look it up on YouTube sounds fun

#

What's good alternative for multiplayer solutions except photon btw?

fleet gorge
#

make your own with websocket 😈

#

but there's not a lot

hasty canopy
#

Noooo 😭

gray mural
fleet gorge
#

for unreal they have their own multiplayer solution built in because epic feeds their Devs
for Godot and every other engine they make their own server code

#

unity is the only engine where there's third party multiplayer solutions

#

meant specifically for the engine

hasty canopy
fleet gorge
#

master one first learn everything then

hasty canopy
#

True true

fleet gorge
#

I've made overcooked multiplayer as a c++ console game before which helped me learn a lot about sockets and multiplayer

#

Give it a try

fleet gorge
#

no engine it's raw c++ printing to console

hasty canopy
#

Wait I'm dumb didn't read properly lmao

fleet gorge
#

so just a bunch of colored squares

#

yuh

fleet gorge
#

I might attempt it again with raylib though

visual burrow
#

Hey guys, Id like to ask for a suggestion on how to visualize connections between two objects - I have a spaceship and "wagon"-like addons to it that are meant to be chained together and attached to the player ship's back, kind of like a train. I've currently implemented it using configurable joints, however I cant think of a good way to visualize the connections. Because its a 3D game and the wagons have a pretty wide range of freedom of movement, it means that sometimes they may get into positions in which a simple line would look a bit awkward, which is why Id like something a bit more "bendy" to connect the wagons. However, physical ropes and such can be quite expensive to simulate, so Id like to avoid using complex physics - is there a simple/hacky way to visualize such a connection?

Gif of ship and wagon placeholders attached as a reference, Id like the lines to be drawn between the ship and wagons

fleet gorge
#

line renderer draw chain texture with transparency

#

set points to the cubes position

#

might need more cubes in between but yea

visual burrow
#

hmmm, is there a good way to calculate intermediate points to give it the appearance of a bend?

#

gotta look into curves ughhh math 😔

fleet gorge
#

the line renderer already comes with curves

#

unless you want more straight lines

visual burrow
#

oh really? good to know thanks! Ive only used a scuffed modified version of line renderer for UI so I wasnt fully aware of what it can and cant do x)

fleet gorge
fleet gorge
#

needs research

#

I'm not sure if you can pass in an animation curve of vector3 in but the editor shows a animation curve

visual burrow
#

yeah yeah

fleet gorge
#

ah ok

#

you got this 🔥

visual burrow
#

diploma project for my uni slowly cooking lol

visual burrow
hasty canopy
visual burrow
hasty canopy
#

That I'm not sure , but few of them inbetween each cubes shouldn't be an issue I think

visual burrow
#

actually, I could technically just use the anchor points of the current joints to pretty much guesstimate the positions of would-be smaller cubes right?

fleet gorge
#

It won't really give a bend shape

#

You can use rotation of the cubes to linecast to each other

hasty canopy
fleet gorge
#

it sounds very weird but hear me out

visual burrow
fleet gorge
#

for the bottom cube, physics spherecast based on transform.up
for the top cube, physics spherecast based on -transform.up

#

use the intersection point

#

as the position for the subcube

hasty canopy
#

Kek, can always swap out mini cubes for chain rings as well then lol

fleet gorge
visual burrow
#

might be worth a shot tho lol

#

i Im gonna be testing out different ways of doing it anyways

brave furnace
#

Is there a way to make this top list serializable?

#

slash editable in the Inspector?

leaden ice
#

And what is EstatModifier?

heady iris
knotty sun
leaden ice
#

basically you'll need those types to be serializable

fleet gorge
leaden ice
#

Oh right also that

fleet gorge
#

Wait ncm

#

It has protected set which could be an issue

heady iris
leaden ice
heady iris
#

protected on the constructor is irrelevant ah, you meant the setter

leaden ice
#

the serializer uses the backing field directly

#

not the accessors

heady iris
fleet gorge
#

You're trying to serialize the child classes

#

But that won't work with just a list

simple egret
#

You named a type "Enum"? That's a no-no, it's a C# system type you shouldn't do that

brave furnace
#

EStat = stat name
EStatModifier = type of modification that this boost will do (i.e. additive, multiplicative, absolute, etc)

fleet gorge
#

Unfortunately they won't give you a drop-down menu to choose between equipmentstats and equipmentattributes

#

You can't serialize it like this

fleet gorge
#

I need this

heady iris
#

I use the Animancer package, which has its own SerializeReference system

fleet gorge
#

Why isn't this part of unity base spinning

heady iris
#

because [SerializeReference] can do much more than just storing a List<Parent>

#

it also allows for you to serialize references between objects

#

although, to be fair, this is all I've ever used the attribute for :p

#

These are lists of abstract classes.

fleet gorge
#

I'm using it for my quest system I need to distinguish between Dialogue Enemy and Puzzle objectives

heady iris
#

Unity would only serialize things from the parent class.

#

It would not understand that you have instances of the child classes in it.

brave furnace
#

This is what I got using [SerlializeReference]. I think I can make something out of this. Thx!

heady iris
#

i do not recognize that UI

#

is that from Odin or something?

brave furnace
#

it's Odin 😄

heady iris
#

ah, there you go

#

so yeah, that'll be exactly what you want

brave furnace
#

yesn't, it's making me question why I don't just make 2 lists 😛

heady iris
#

well, maybe you'll add a third type!

#

or a fourth!

leaden ice
#

probably start with learning the basics of Unity and programming

brave furnace
#

That is obviously what I meant to say

#

Thx 😄

leaden ice
#

Don't jump directly into a voxel game as that's a bit more intermediate/advanced

#

(assuming you mean minecraft-like)

rigid island
#

no lol

brave furnace
#

I recommend following some tutorials to get an idea of game development in general. Brackey's is a good play to start 🙂

leaden ice
#

There are similarities and differences. But C# is quite different from JavaScript

#

Start with learning the basics

#

It's tempting to try to dive straight into your dream game

#

but... you will definitely fail if you try that

brave furnace
#

been working on my dream game for 10+ years now 💪

opaque vortex
#

Can I use the drag and drop unity offers for coding I saw online to make a voxel game, or should I start learning c#?

brave furnace
#

I highly recommend learning C#

leaden ice
rigid island
#

Visual Scripting will be diffcult

#

and a mess

opaque vortex
brave furnace
#

yes

rigid island
#

yea they have the same components

brave furnace
#

it's possible, but if you're making complex code, visual scripting becomes quite... convoluted

rigid island
#

blueprint flashbacks

brave furnace
#

oh boy, that is very ambitious

#

but yes, it is possible

rigid island
#

yes its bad

opaque vortex
#

I know in coding for a project you have to make it possible for other developers to be able to work on it, avoiding a yandere dev situation. But would visual scripting a whole minecraft like game, would it be dangerous?

rigid island
#

you wont get far anyway with that, you should learn the basics first and make simple projects

rigid island
leaden ice
#

It would certainly be VERY difficult to collaborate with other developers using visual scripting

chilly surge
#

How does visual scripting deal with merge conflicts? Just pure pain?

brave furnace
#

if you're woried about good coding practices, i recommend checking "Clean Architecture" by Uncle Bob out. He defines a concept called SOLID which will streamline coding processes 🙂

opaque vortex
#

Can I use visual scripting for the most part then reorganize the code as I learn c# or is that a dumb idea again

rigid island
#

mymans obsessed with VS

#

the logic/components will mostly be the same but seems silly to start with VS

#

c# is very human-friendly

brave furnace
opaque vortex
rigid island
#

if u know JS just seems silly to go backwards with Visual Script

opaque vortex
rigid island
#

tryitandsee ig

opaque vortex
rigid island
#

coding a game in general isn't easy

brave furnace
#

it's easy, but also limited in the amount of resources you have about it. If you were to make, for example, an inventory system, you might find 1 or 2 videos that do it through visual scripting, while a regular C# version can be obtained by a plethora of sources, you could even ask ChatGPT.

rigid island
#

no gpt

opaque vortex
rigid island
#

yes same with any other code

#

LLMS don't reason or logic

#

they just regurgitate info based on database match

brave furnace
#

🤷 it's really powerful, it's helped me quite a bit before

#

github copilot is 🔥

rigid island
#

yeah everyone says the same thing but turns out they made simple kiddie scripts with it

#

copilot is more legit because its more like predictive code based on other code you wrote

brave furnace
#

well yeah, that's what most of our scripts are. Small, self contained scripts.

rigid island
#

ehh better to just learn the right way

paper flame
brave furnace
rigid island
# paper flame what

seems you're trying to call some unity API in separate thread, this isn't allowed

paper flame
#

I tried to fix that with ```cs
using System;
using System.Collections.Generic;
using UnityEngine;

public class UnityMainThreadDispatcher : MonoBehaviour
{
private static readonly Queue<Action> _executionQueue = new Queue<Action>();

private static UnityMainThreadDispatcher _instance = null;

public static UnityMainThreadDispatcher Instance()
{
    if (!_instance)
    {
        var go = new GameObject("UnityMainThreadDispatcher");
        _instance = go.AddComponent<UnityMainThreadDispatcher>();
        DontDestroyOnLoad(go);
    }
    return _instance;
}

public void Enqueue(Action action)
{
    lock (_executionQueue)
    {
        _executionQueue.Enqueue(action);
    }
}

private void Update()
{
    lock (_executionQueue)
    {
        while (_executionQueue.Count > 0)
        {
            _executionQueue.Dequeue().Invoke();
        }
    }
}

}```

rigid island
somber nacelle
#

yeah accessing that singleton from anywhere other than the main thread if it does not already exist will fail because instantiating it can only be done on the main thread

paper flame
#

huh

#

well illook again at my matchmaking

#

man I hate multiplayer with my life

rigid island
#

I mean this is more to do with multi-threading not multiplayer

paper flame
#

I know

#

screwed that one too

#

I love today

rigid island
#

unless it was like JOBS unity doesn't like its functions being out main thread so fix that lol

somber nacelle
#

are we even certain this is related to multiplayer or threading? this could easily just be trying to instantiate something in a field initializer or some object's constructor during scene load

paper flame
#

this is the only thing happening

#

Not seeing where I did anything outside main-thread

#

But I am pretty blind

leaden ice
rigid island
#

is UnityMainThreadDispatcher some custom class or something

leaden ice
#

this handler almost certainly runs on a background thread

leaden ice
#

unless they do some magic for you

somber nacelle
paper flame
#

I can use Coroutines

#

i think

#

for it

somber nacelle
#

like i said before, since it gets instantiated if it does not exist it will fail if you only ever check it off of the main thread

paper flame
#

yeah okay

#

lets look

#

since when is FindObjectofType deprecated btw

somber nacelle
#

since 2022 when it was replaced with FindObjectByType or whatever the new one is called that doesn't automatically do sorting by instance id

#

why do you even need to use it anyway. literally just call UnityMainThreadDispatcher.Instance() in Start

rigid island
#

the new one (FindFirstObjectByType)

paper flame
somber nacelle
#

just call it as the first line in Start. all that will do is ensure that the instance exists before you do anything off of the main thread

paper flame
#

aaaa

#

well I fixed the issue

#

Got another one now

somber nacelle
paper flame
#

pff

somber nacelle
#

you could cache the result of the Instance() call and just use the cached value instead of calling that method again to access the singleton

graceful crater
paper flame
#

Like ```cs
using System;
using System.Collections.Generic;
using UnityEngine;

public class UnityMainThreadDispatcher : MonoBehaviour
{
private static readonly Queue<Action> _executionQueue = new Queue<Action>();

private static UnityMainThreadDispatcher _instance = null;
private static bool _initialized = false;

public static UnityMainThreadDispatcher Instance()
{
    if (!_initialized)
    {
        _instance = FindObjectOfType<UnityMainThreadDispatcher>();
        if (_instance == null)
        {
            var go = new GameObject("UnityMainThreadDispatcher");
            _instance = go.AddComponent<UnityMainThreadDispatcher>();
            DontDestroyOnLoad(go);
        }
        _initialized = true;
    }
    return _instance;
}

public void Enqueue(Action action)
{
    lock (_executionQueue)
    {
        _executionQueue.Enqueue(action);
    }
}

private void Update()
{
    lock (_executionQueue)
    {
        while (_executionQueue.Count > 0)
        {
            _executionQueue.Dequeue().Invoke();
        }
    }
}

}

and then in start   dispatcher = UnityMainThreadDispatcher.Instance();?
latent latch
#
public abstract class Singleton<T> : StaticInstance<T> where T : MonoBehaviour
{
    protected override void Awake()
    {
        if (Instance != null)
        {
            Debug.Log(gameObject.name + " singleton confliction");
            Destroy(gameObject);
        }
        base.Awake();
    }
}

So my singletons have DontDestroyOnLoad() on them for scene changing, but if I change to a scene that original spawns the singletons, I get the confliction which I need to resolve by removing the newest one from the scene. However, it seems this method of resolving also destroys the Instance reference of the original singleton, even though it still exists in the scene. Any idea how to resolve this?

#

My idea is just make a main Main menu to never go back into and load all the singletons there

leaden ice
#

base.Awake() is still going to run after you call Destroy here

#

which... depends on what's in there, but it will likely assign Instance = this;?

latent latch
#
public abstract class StaticInstance<T> : MonoBehaviour where T : MonoBehaviour
{
    public static T Instance { get; private set; }
    protected virtual void Awake() => Instance = this as T;

    protected virtual void OnDestroy()
    {
        Instance = null;
    }
}```
leaden ice
#

yeah...

#
public abstract class Singleton<T> : StaticInstance<T> where T : MonoBehaviour
{
    protected override void Awake()
    {
        if (Instance != null)
        {
            Debug.Log(gameObject.name + " singleton confliction");
            Destroy(gameObject);
            return;
        }
        base.Awake();
    }
}```
#

do this, no?

latent latch
#

lemme try

gray mural
latent latch
#

blah, I don't usually work with multiple scenes, especially with moving singletons around

#

but kinda dont want the audio bg just cutting out

ripe wave
# gray mural What exactly is not working?

where should i attatch the script i have it to my player, should i attach it to GameOverScreen object or no? because the sound still don't dissapier and i think i need also to disable playercontrolls because when it starts walking the audio source starts playing

gray mural
#
    1. Which script should disable it?
    1. Which script checks for the GameObjectOverScreen to show up?
    1. Which script checks for the player being dead?
ripe wave
gray mural
#

Also I wonder why you would add a "Script" after its name if it's already a script. Simply GameManager

#

GameManagers are usually Singletons. This makes it easier for the other objects to reference them.

#

I would suggest you make it a Singeton. If you don't know what that it, you should google it.

#

Create a simple generic Singleton<T> and derive the GameManager class from it. Access the boolean using GameManager.Instance.yourBoolean in the other scripts when required

ripe wave
#

okey, i will try

gray mural
ripe wave
gray mural
#

Singletons make you able to reference the class using the Instance

#

This way, the class derived from the Singleton<T> acts as a "static class", you can say

public class GameManager : Singleton<GameManager>
{
    public bool yourBool;
}

// access the GameManager's variable from another class
// without having a variable to reference it
GameManager.Instance.yourBool;
#

This should be enough for you to understand, I suppose

gray mural
#

More than 1 MonoBehaviour cannot exist in a single script. It's going to throw you an error. Add the Singleton to the another script and, have you even seen the links I've sent? Simply copy the code from there and remove the commects if required.

shell scarab
#

Also I don’t see any MonoBehaviour definitions in that script?

#

So not quite sure what you’re talking about when replying to that

ripe wave
#

Im gonna go watch youtube tutorials nothing works for me

heady iris
#

these are not monobehaviours

shell scarab
ripe wave
shell scarab
#

"automatic" doesn't really exist, you gotta code it yourself

ripe wave
#

yea i know

#

that

shell scarab
#

What have you tried?

ripe wave
#

i tried adding thoose Singletons

#

but i deleted them i don't understand them

shell scarab
#

Ok, so what triggers the game over screen?

ripe wave
#

Player isDead

shell scarab
#

not sure what that means

ripe wave
#

when player is dead

#

it shows up

shell scarab
#

magically?

ripe wave
#

and i have GameManager

#

no

#

with script

shell scarab
#

So the GameManager triggers it?

#

ok, so you already know when the player is dead. What's the problem? Just put the code there to disable the things you want

unborn dirge
#

any idea why this happens

shell scarab
#

yea

#

the protection level is making it inaccessible....

unborn dirge
#

lemme rephrase

leaden ice
unborn dirge
#

how can i fix it

leaden ice
#

change the protection level

unborn dirge
#

how do i do that

shell scarab
#

you learn c#

leaden ice
#

make it public

shell scarab
#

what's the command for learning c#?

unborn dirge
#

i see

#

this is not beginner

shell scarab
#

this problem is extremely beginner

unborn dirge
leaden ice
#

looks like you made a duplicate variable in this script for some reason

#

that's completely unecessary and actually will probably cause bugs

unborn dirge
#

im watching a guys video and it causes him no issue

leaden ice
#

the second problem is, again, you don't have the right access modifier on PlayerMovement.isFacingRight to be able to access it here.

leaden ice
unborn dirge
#

im sure i did

leaden ice
#

I'm sure you didn't

somber nacelle
shell scarab
#

this sort of thing is not something that changes with a Unity update, it's definitely copied wrong

leaden ice
#

yup

unborn dirge
# somber nacelle link the video and show the full relevant code

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH

In this Unity tutorial, we'll be re-creating Hollow Knight's camera system using Unity and Cinemachine.

We're going to cover...

▶ Play video
#

This is what he did

shell scarab
#

Already I can see that your code says _player.isFacingRight and his says _player.IsFacingRight, so that's one thing copied wrong.

leaden ice
#

no this is what he did

#

You're looking at the wrong script

unborn dirge
#

i mean

somber nacelle
#

another one for the counter

unborn dirge
#

i've done the movement in a different way

leaden ice
#

ok but

#

that doesn't let you write invalid C#

#

Anyway I think this tutorial is a bit too advanced for you

unborn dirge
#

I know

leaden ice
#

and especially if you don't know the basics yet and they go thorugh the code EXTREMELY fast here

unborn dirge
#

i see..

leaden ice
#

so it's expected you already sorta know how the basics

shell scarab
#

honestly just learn good old regular c# first, don't jump straight into unity.

unborn dirge
#

its for a project to be fair thats why im watching a video, im planning to learn c# after but the deadline is soon so i dont have time for that + we didnt have time in the beginning

#

my teachers are pretty shit anyways

#

but thank you anyway

shell scarab
#

school semesters are ending about now, I think you had time to learn c# first.

leaden ice
# leaden ice

Anyway as you can see the variable is public in the PLayer script and in fact it's a property and not a field, but that won't make a huge difference

unborn dirge
#

i dont live in the us

shell scarab
#

Well I find it hard to believe the teacher gave an assignment with something you've never seen before and said ok its due in a week or something

unborn dirge
#

believe me it is

#

he expects us to just watch videos to make a game

shell scarab
#

I don't, but your best bet is to learn c# first then follow that video. I suggest codeacademy https://www.codecademy.com/catalog/language/c-sharp do the "Learn C#" lesson, it shouldn't take you too long compared to trying to struggle through the video without knowing

unborn dirge
#

its an awful college that doesnt teach at all, rather they encourage us to google or copy off other students

paper flame
#

I am pretty stuck on this for a hour now
https://hastebin.skyra.pw/gegebesewe.csharp

NullReferenceException: Object reference not set to an instance of an object.
Movement+<InitializeSocket>d__32.MoveNext () (at Assets/Scripts/Player/Movement.cs:201)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <fe22fa1c9ce44af491c6d67e6c35b4a4>:0)

once the player matched
I think this causes the player to not be able to move

leaden ice
shell scarab
#

I believe tileMapGen is null, since seed seems like it would be an int or uint based on your other code

leaden ice
#

The only things that can be null here and cause this error are:
tileMapGen OR tileMapGen.seed

paper flame
#

the object?

#

wait

leaden ice
#

Figure out which one is null

#

and fix it

paper flame
#

ty

leaden ice
#

BTW

#

doesn't seem like you even use seedState at all

#

so maybe just delete the line?

#

wait nvm you do I see it

paper flame
#

But the problem kinda is the player prefab when I try to assing them in the inspector will do

shell scarab
#

also be careful with those lambdas and those interfaces. Those lambdas are being subscribed to an event it looks like, and if the object that script is attatched to is unloaded the event will have a null reference and stop propogating that event.

As for the interfaces they don't serialize in the inspector.

paper flame
#

when I am ingame the Tile map gen is indeed empty

leaden ice
#

But this:

        var seedState = new Dictionary<string, string> { { "seed", tileMapGen.seed.ToString() } };
        var seedStateJson = JsonConvert.SerializeObject(seedState);
        var seedStateBytes = Encoding.UTF8.GetBytes(seedStateJson);```
Seems like a really roundabout way of just writing this:
```cs
var seedStateBytes = Encoding.UTF8.GetBytes($"{ \"seed\": {tileMapGen.seed} }");```
shell scarab
#

"Type mismatch"

#

what could that mean?

paper flame
#

Well should I do it this way then? I am pretty confusefd

shell scarab
#

What do you think "Type mismatch" means

paper flame
#

that the object type is not the right fit

shell scarab
#

Great! So why don't you check what you're dragging into there

paper flame
#

I am dragging exactly what supposes to be dragged into it, and it works ingame just not in the editor somehow

shell scarab
#

ok, show me what you're dragging into there, and show me what object that screenshot is from

paper flame
#

when I make it a prefab this happens

#

This screenshot is from the Player Object

shell scarab
#

great! Now show it to me

#

like the object

#

and show me the object you're trying to drag into there

#

Because you said it only happens when you make it a prefab

#

which is weird, but perhaps it's trying to tell you it's a scene object and those can't be dragged into a prefab file

paper flame
#

this is if I do it in the scene itself

leaden ice
paper flame
#

oh

leaden ice
#

Is the tilemap generator a singleton?

#

You can use that

#

otherwise pass the reference to this script when you spawn the Player

#

seems kinda weird that your player cares about the tilemap generator at all to be honest though

#

I believe you have some separation of concerns issues

#

your player script is doing too much

paper flame
leaden ice
#

you could also just pass the player the seed itself

#

rather than the whole tilemap generator

#

if you just need it for the seed

paper flame
#

thanks, it worked

#

But you think i need to split my movement class? xD

#

Youre right

leaden ice
#

I mean it's called "movement" but just based on those variables it's also doing:

  • Interaction with objects
  • Punching
ripe wave
#

Any ideas?

shell scarab
latent latch
#
public IEnumerator PreloadMusic()
{
    audio.bg_source.volume = 0.0f;
    audio.bg_source.clip = audio.Game_BG_Clip;
    audio.bg_source.Play();
    yield return new WaitForSeconds(2);
    audio.bg_source.clip = audio.Boss_BG_Clip;
    audio.bg_source.Play();
    yield return new WaitForSeconds(2);
    audio.ChangeBGMusicState(BGMusic.MainMenu);
    yield return new WaitForSeconds(2);
    musicPreloaded = true;
}```
What is the actual way to prewarm your audio because this is my fix here
#

you should see what I do to prewarm my shader cache

shell scarab
latent latch
#

my god you may be right

shell scarab
#

If you don't expect it to play right away you can also check off the "load in background" thing so it doesn't make the scene loading take longer

latent latch
#

now to figure out the shader cache issue but I looked for boxes for that

#

there is an editor method for it but I've not seen anything else

shell scarab
#

shader cache issue?

latent latch
#

first time a shader becomes used somethings I get a hiccup, but I'm talking about hundreds of shaders sometimes showing up at once

#

so there is some pre-warming issue it seems

shell scarab
#

it's probably just an editor thing, wouldn't happen in a build

latent latch
#

it's funny I was watching some godot video and the dude blacks out his scene for a second and loads every object in front of the camera to cache it all

shell scarab
#

I'm pretty sure you won't have a problem in a build

latent latch
#

i've built and it persists. I think it's more of a webgl issue though

shell scarab
#

Well there's a method: Shader.WarmupAllShaders(), it ays it prewarms all shader variants of all shaders currently in memory. It says DX12, Vulkan, and Metal might not work correctly.

latent latch
#

honestly, sticking stuff in front of the camera seems to be the idea as that does actually work

shell scarab
#

what specifically is happening?

latent latch
#

first time a new shader variant object is rendered, Unity must be making and cachign the buffer then

shell scarab
#

There's also "ShaderWarmup.WarmupShader" But it's marked as experimental

latent latch
#

but that's a problem when rendering multiple new shaders at once

shell scarab
#

but whats the effect that's happening, and how is it happening

latent latch
#

windows build I think the method may have work? But no difference in a webgl build

shell scarab
#

well try the second experimental one

#

but maybe you need a shader variant collection and prewarm it?

latent latch
#

probably something like that yeah. The camera idea does work though so I'll always fall back onto that if not.

shell scarab
#

ok, i still dont know whats happening other than there's some vague problem

latent latch
#

not vague. It's how the shaders are being cached. It doesnt warm shaders apparently so there's something additional work to be done

#

I don't know how to be more clear on that.

shell scarab
#

yea, what is the result of this?